Skip to content

HttpClientError

Typed failure model for Effect HTTP client operations.

HTTP clients wrap request construction, transport, status-code validation, and response decoding failures in HttpClientError. The wrapper keeps the failed request and the specific failure reason together, so callers can handle client failures uniformly while still matching on the reason _tag for retry policy, logging, metrics, and user-facing messages.

12 exports Added in v4.0.0 Source

Errors

DecodeError

Added in v4.0.0 Source

Response error for failures while decoding an HTTP response body.

Signature

declare class DecodeError extends YieldableError<this> & {
  readonly _tag: "DecodeError";
} & Readonly<{
  readonly cause?: unknown;
  readonly description?: string;
  readonly request: HttpClientRequest;
  readonly response: HttpClientResponse;
}> {
  constructor(args: {
    readonly cause?: unknown;
    readonly description?: string;
    readonly request: HttpClientRequest;
    readonly response: HttpClientResponse;
  });
  message: string;
  methodAndUrl: string;
}

Response error for operations that expected a response body but received an empty body.

Signature

declare class EmptyBodyError extends YieldableError<this> & {
  readonly _tag: "EmptyBodyError";
} & Readonly<{
  readonly cause?: unknown;
  readonly description?: string;
  readonly request: HttpClientRequest;
  readonly response: HttpClientResponse;
}> {
  constructor(args: {
    readonly cause?: unknown;
    readonly description?: string;
    readonly request: HttpClientRequest;
    readonly response: HttpClientResponse;
  });
  message: string;
  methodAndUrl: string;
}

EncodeError

Added in v4.0.0 Source

Error describing failures while encoding an HTTP request body.

Signature

declare class EncodeError extends YieldableError<this> & {
  readonly _tag: "EncodeError";
} & Readonly<{
  readonly cause?: unknown;
  readonly description?: string;
  readonly request: HttpClientRequest;
}> {
  constructor(args: {
    readonly cause?: unknown;
    readonly description?: string;
    readonly request: HttpClientRequest;
  });
  message: string;
  methodAndUrl: string;
}

Error wrapper for HTTP client failures, exposing the failed request and the optional response through its reason.

Signature

declare class HttpClientError extends YieldableError<this> & {
  readonly _tag: "HttpClientError";
} & Readonly<{
  readonly reason: HttpClientErrorReason;
}> {
  constructor(props: {
    readonly reason: HttpClientErrorReason;
  });
  readonly "~effect/http/HttpClientError": "~effect/http/HttpClientError";
  message: string;
  request: HttpClientRequest;
  response: HttpClientResponse | undefined;
}

Union of all specific failure reasons carried by HttpClientError.

Signature

type HttpClientErrorReason = RequestError | ResponseError;

Error describing failures while constructing a URL from an HTTP client request.

Signature

declare class InvalidUrlError extends YieldableError<this> & {
  readonly _tag: "InvalidUrlError";
} & Readonly<{
  readonly cause?: unknown;
  readonly description?: string;
  readonly request: HttpClientRequest;
}> {
  constructor(args: {
    readonly cause?: unknown;
    readonly description?: string;
    readonly request: HttpClientRequest;
  });
  message: string;
  methodAndUrl: string;
}

RequestError type

Added in v4.0.0 Source

Union of HTTP client errors that occur before a response is available.

Signature

type RequestError = TransportError | EncodeError | InvalidUrlError;

ResponseError type

Added in v4.0.0 Source

Union of HTTP client errors that include an HTTP response.

Signature

type ResponseError = StatusCodeError | DecodeError | EmptyBodyError;

Response error for HTTP responses rejected because of their status code.

Signature

declare class StatusCodeError extends YieldableError<this> & {
  readonly _tag: "StatusCodeError";
} & Readonly<{
  readonly cause?: unknown;
  readonly description?: string;
  readonly request: HttpClientRequest;
  readonly response: HttpClientResponse;
}> {
  constructor(args: {
    readonly cause?: unknown;
    readonly description?: string;
    readonly request: HttpClientRequest;
    readonly response: HttpClientResponse;
  });
  message: string;
  methodAndUrl: string;
}

Error describing transport-level failures that occur while sending an HTTP request.

Signature

declare class TransportError extends YieldableError<this> & {
  readonly _tag: "TransportError";
} & Readonly<{
  readonly cause?: unknown;
  readonly description?: string;
  readonly request: HttpClientRequest;
}> {
  constructor(args: {
    readonly cause?: unknown;
    readonly description?: string;
    readonly request: HttpClientRequest;
  });
  message: string;
  methodAndUrl: string;
}

Guards

Returns true when a value is an HttpClientError.

Signature

declare function isHttpClientError(u: unknown): u is HttpClientError;

Schemas

Schema for serializable HTTP client errors, preserving the specific error kind and cause.

Signature

declare class HttpClientErrorSchema extends {
  readonly _tag: "HttpError";
  readonly cause?: unknown;
  readonly kind: "TransportError" | "EncodeError" | "InvalidUrlError" | "StatusCodeError" | "DecodeError" | "EmptyBodyError";
} & YieldableError<this> {
  constructor(...args: [props: {
    readonly _tag?: "HttpError";
    readonly cause?: unknown;
    readonly kind: "TransportError" | "EncodeError" | "InvalidUrlError" | "StatusCodeError" | "DecodeError" | "EmptyBodyError";
  }, options?: MakeOptions]);
  static fromHttpClientError(error: HttpClientError): HttpClientErrorSchema;
}