Class DefaultErrorHandler
Handles errors in HTTP responses by mapping status codes to common exception types.
public class DefaultErrorHandler : IErrorHandler
- Inheritance
-
DefaultErrorHandler
- Implements
- Inherited Members
Methods
ExtractMessage(string, MediaTypeHeaderValue?)
Tries to extract an error message from the response body.
protected virtual string? ExtractMessage(string body, MediaTypeHeaderValue? contentType)
Parameters
bodystringThe response body in string form.
contentTypeMediaTypeHeaderValueThe content type of the response body.
Returns
HandleAsync(HttpResponseMessage)
Throws appropriate Exceptions based on HTTP status codes and response bodies.
public Task HandleAsync(HttpResponseMessage response)
Parameters
responseHttpResponseMessage
Returns
Exceptions
- InvalidDataException
- AuthenticationException
- UnauthorizedAccessException
- KeyNotFoundException
- InvalidOperationException
Conflict, PreconditionFailed or RequestedRangeNotSatisfiable
- HttpRequestException
Other non-success status code.
MapException(HttpStatusCode, string)
Maps the HTTP status code to an exception.
protected virtual Exception MapException(HttpStatusCode statusCode, string message)
Parameters
statusCodeHttpStatusCodeThe status code.
messagestringAn error message to include in the exception.