What is the best way to handle a response in RestSharp?

I am using RestSharp and I want to know what works best for an answer. There RestResponseis ErrorMessage, ErrorExceptionand ResponseStatus, but how can I check if the request was successful?

I am using this code. Does this look normal?

if (response.ResponseStatus != ResponseStatus.Completed)
{
    throw new ApplicationException(response.ErrorMessage);
}
+4
source share
2 answers

This does not always catch all errors. As Jacob said, it ResponseStatuscan be Completed, even if it returns 404 or some other bad status.

Instead, use one StatusCodethat processes all responses HttpStatus.

if (response.StatusCode != System.Net.HttpStatusCode.OK)
  throw new ApplicationException(response.ErrorMessage);
+5
source

It is right. you can process another type of response by agreement

-1
source

All Articles