Return type definition for the HttpError.toJSON method

This interface provides a structured representation of all HTTP error information in a format suitable for serialization, logging, debugging, and API responses. It ensures consistency across different parts of an application when handling HTTP errors.

The generic type parameter T allows for type-safe access to the parsed response body when the structure is known at compile time.

  // Using with known error response structure
interface ApiErrorResponse {
code: string;
message: string;
details?: Record<string, any>;
}

const errorProps: HttpError.IProps<ApiErrorResponse> = httpError.toJSON<ApiErrorResponse>();
console.log(errorProps.message.code); // Type-safe access to error code
interface IProps<T> {
    headers: Record<string, string | string[]>;
    message: T;
    method: "HEAD" | "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
    path: string;
    status: number;
}

Type Parameters

  • T

    The type of the message field (parsed response body)

Properties

headers: Record<string, string | string[]>

The response headers as key-value pairs (values can be string or string array)

message: T

The response body (either parsed JSON object or original string)

method: "HEAD" | "GET" | "POST" | "PUT" | "PATCH" | "DELETE"

The HTTP method used for the request

path: string

The path or URL that was requested

status: number

The HTTP status code returned by the server