Table of Contents

Class DefaultErrorHandler

Namespace
TypedRest.Errors
Assembly
TypedRest.dll

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 string

The response body in string form.

contentType MediaTypeHeaderValue

The content type of the response body.

Returns

string

HandleAsync(HttpResponseMessage)

Throws appropriate Exceptions based on HTTP status codes and response bodies.

public Task HandleAsync(HttpResponseMessage response)

Parameters

response HttpResponseMessage

Returns

Task

Exceptions

InvalidDataException

BadRequest

AuthenticationException

Unauthorized

UnauthorizedAccessException

Forbidden

KeyNotFoundException

NotFound or Gone

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 HttpStatusCode

The status code.

message string

An error message to include in the exception.

Returns

Exception