Table of Contents

Class HttpErrorMapper

Namespace
CivitaiSharp.Core.Response
Assembly
CivitaiSharp.Core.dll

Provides utilities for mapping HTTP responses to Error instances. Centralizes HTTP error handling logic including RFC 7807 problem details parsing for consistent behavior across CivitaiSharp libraries.

public static class HttpErrorMapper
Inheritance
HttpErrorMapper
Inherited Members

Remarks

This class is public to allow custom HTTP client implementations to use the same error mapping logic.

When parsing RFC 7807 error responses, only the standard fields useful for client-side error handling are extracted (type, title, status, detail, instance, errors, traceId). Custom RFC 7807 extension fields are intentionally not exposed as they are typically server-implementation-specific and not actionable by client code.

Methods

BuildCloudflareErrorMessage(string, int, string)

Builds a detailed error message for Cloudflare errors.

public static string BuildCloudflareErrorMessage(string errorType, int statusCode, string contentType)

Parameters

errorType string

The detected Cloudflare error type.

statusCode int

The HTTP status code.

contentType string

The content type of the response.

Returns

string

A formatted error message.

DetectCloudflareErrorType(string)

Detects the type of Cloudflare error page from the response content.

public static string? DetectCloudflareErrorType(string content)

Parameters

content string

The HTML content of the response.

Returns

string

The detected Cloudflare error type, or null if not a Cloudflare error.

FromHttpRequestException(HttpRequestException)

Creates an Error from an HttpRequestException.

public static Error FromHttpRequestException(HttpRequestException exception)

Parameters

exception HttpRequestException

The HTTP request exception.

Returns

Error

An error representing the exception.

FromHttpResponse(HttpStatusCode, string?, string?, RetryConditionHeaderValue?)

Creates an Error from an HTTP response.

public static Error FromHttpResponse(HttpStatusCode statusCode, string? content, string? reasonPhrase, RetryConditionHeaderValue? retryAfter)

Parameters

statusCode HttpStatusCode

The HTTP status code.

content string

The response body content, if available.

reasonPhrase string

The HTTP reason phrase, if available.

retryAfter RetryConditionHeaderValue

The Retry-After header value, if available.

Returns

Error

An error representing the HTTP response.

FromTimeout(Exception?)

Creates an Error for a timeout.

public static Error FromTimeout(Exception? exception = null)

Parameters

exception Exception

The exception that caused the timeout.

Returns

Error

An error representing the timeout.

GetRetryAfter(RetryConditionHeaderValue?)

Extracts the Retry-After duration from response headers.

public static TimeSpan? GetRetryAfter(RetryConditionHeaderValue? retryAfter)

Parameters

retryAfter RetryConditionHeaderValue

The Retry-After header value.

Returns

TimeSpan?

The retry delay, or null if not specified.

MapStatusCode(HttpStatusCode)

Maps an HTTP status code to the corresponding ErrorCode.

public static ErrorCode MapStatusCode(HttpStatusCode statusCode)

Parameters

statusCode HttpStatusCode

The HTTP status code to map.

Returns

ErrorCode

The corresponding error code.