'What exception to throw when you get 500 response code
I want to know what type of exception to throw when I get 500 response code. I have my code something like
_logger is Microsoft.Extensions.Logging
HttpResponseMessage response = await Something.configureAwait(false);
if(response.IsSuccessStatusCode)
{
//do something as it is 200 response
}
else if(response.StatusCode == HttpStatusCode.InternalServerError || response.StatusCode == HttpStatusCode.RequestTimeOut)
{
_logger.LogError(response.StatusCode + "some Message");
throw new HttpResponseException //error : type or namespace could not be found
}
else
{
_logger.LogError(response.StatusCode + "some Message");
//Any other error code it means, there is something wrong in my code like 400, 404 (I passed incorrect url), 203 (again my issue).
}
I just want the user to retry if it is 500 and for the other cases, I would take care with unit test. Any suggestion is welcomed.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
