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
body
stringThe response body in string form.
contentType
MediaTypeHeaderValueThe 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
response
HttpResponseMessage
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
statusCode
HttpStatusCodeThe status code.
message
stringAn error message to include in the exception.