RESTCLIENT.NET
Menu
EN
↗ GitHub

RESTCLIENT.NET / API REFERENCE

Outcome.HttpError<TError>

All API types · Outcome · View source

public abstract partial record HttpError<TError>

Represents HTTP-specific errors that can occur during web requests. This sealed hierarchy ensures complete error handling coverage for HTTP operations. Follows the functional programming principle of making illegal states unrepresentable by using a discriminated union instead of inheritance hierarchies.

Type parameter TError: The type representing parsed error response bodies.

Members

FromErrorResponse

public static HttpError<TError> FromErrorResponse(TError body, HttpStatusCode statusCode, HttpResponseHeaders headers);

Creates an HttpError from an error response. This is the canonical way to represent structured API errors.

Parameter Type Default Description
body TError Required The parsed error response body.
statusCode HttpStatusCode Required The HTTP status code.
headers HttpResponseHeaders Required The HTTP response headers.

Returns: An ErrorResponseError containing the error details.

View source: Outcome/HttpError.cs:76

FromException

public static HttpError<TError> FromException(Exception exception);

Creates an HttpError from an exception. This is the canonical way to represent infrastructure errors.

Parameter Type Default Description
exception Exception Required The exception that occurred.

Returns: An ExceptionError containing the exception.

View source: Outcome/HttpError.cs:65

IsErrorResponseError

public bool IsErrorResponseError(out TError body, out HttpStatusCode statusCode, out HttpResponseHeaders? headers);

Attempts to extract the ErrorResponseError details from this HttpError. Returns true if this is an ErrorResponseError and outputs the details. Returns false if this is an ExceptionError.

Parameter Type Default Description
body TError Required The error response body if ErrorResponseError, default otherwise.
statusCode HttpStatusCode Required The HTTP status code if ErrorResponseError, default otherwise.
headers HttpResponseHeaders? Required The HTTP response headers if ErrorResponseError, null otherwise.

Returns: True if ErrorResponseError, false if ExceptionError.

View source: Outcome/ErrorResponseError.cs:48

Match

public TError Match(Func<Exception, TError> onException, Func<TError, HttpStatusCode, HttpResponseHeaders, TError> onErrorResponse);

Transforms this HttpError into a new type using the provided functions. This is the catamorphism for HttpError, enabling complete pattern matching.

Parameter Type Default Description
onException Func<Exception, TError> Required Function to apply if this is an ExceptionError.
onErrorResponse Func<TError, HttpStatusCode, HttpResponseHeaders, TError> Required Function to apply if this is an ErrorResponseError.

Returns: The result of applying the appropriate function.

View source: Outcome/HttpError.cs:43

IsErrorResponse

public bool IsErrorResponse { get; }

Gets a value indicating whether this error was caused by an HTTP error response.

View source: Outcome/HttpError.cs:34

IsExceptionError

public bool IsExceptionError { get; }

Gets a value indicating whether this error was caused by an exception.

View source: Outcome/HttpError.cs:29