I was wondering if there was an easier way (nicer way) to check for a 500 status code?
The only way I can think of doing this is by doing:
var statusCodes = new List<HttpStatusCode>()
{
HttpStatusCode.BadGateway,
HttpStatusCode.GatewayTimeout,
HttpStatusCode.HttpVersionNotSupported,
HttpStatusCode.InternalServerError,
HttpStatusCode.NotImplemented,
HttpStatusCode.ServiceUnavailable
};
if (statusCodes.Contains(response.StatusCode))
{
throw new HttpRequestException("Blah");
}
I noticed these are the 500 types:
The Status codes starting with 5xx is a server error, so the simple method would be
if ((int)response.StatusCode>=500 && (int)response.StatusCode<600)
throw new HttpRequestException("Server error");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With