Skip to content

HttpServerError.ts

Describes failures raised while handling HTTP server requests.

HttpServerError covers failures that happen while accepting a request, matching a route, running a handler, or building and sending a response. Request-scoped failures keep the request that caused them, and response failures keep the response being produced. This module also includes helpers for turning failed causes or exits into HTTP responses and an annotation for interrupts caused by client aborts.

Since v4.0.0



Context annotation used to mark an interrupt as caused by the client aborting the request.

Details

causeResponse uses this annotation to map a pure client abort to a 499 response instead of a server abort response.

Signature

declare class ClientAbort

Source

Since v4.0.0

Converts a failed handler cause into the HTTP response that should be sent and the cause that should be reported.

Details

Respondable failures and defects can choose their own response, defects that are already HttpServerResponse values are used directly, and pure interrupts produce either 499 for client aborts or 503 for server aborts.

Signature

declare const causeResponse: <E>(
cause: Cause.Cause<E>
) => Effect.Effect<readonly [Response.HttpServerResponse, Cause.Cause<E>]>

Source

Since v4.0.0

Derives an HTTP response from a failed handler cause synchronously.

Details

If the cause contains a defect that is already an HttpServerResponse, that response is used and removed from the remaining cause. Otherwise the response defaults to 500.

Signature

declare const causeResponseStripped: <E>(
cause: Cause.Cause<E>
) => readonly [response: Response.HttpServerResponse, cause: Option.Option<Cause.Cause<E>>]

Source

Since v4.0.0

Extracts the response from a successful handler exit, or derives a response from the failure cause.

Signature

declare const exitResponse: <E>(exit: Exit.Exit<Response.HttpServerResponse, E>) => Response.HttpServerResponse

Source

Since v4.0.0

Tagged error for failures that occur while handling an HTTP server request.

Details

It wraps a HttpServerErrorReason, exposes the associated request and optional response, and can be converted to an HTTP response through the Respondable protocol.

Signature

declare class HttpServerError {
constructor(props: { readonly reason: HttpServerErrorReason })
}

Source

Since v4.0.0

Signature

declare const [Respondable.symbol]: () => Effect.Effect<Response.HttpServerResponse, never, never>

Source

Signature

readonly [TypeId]: "~effect/http/HttpServerError"

Source

Signature

stack: string

Source

Reason carried by an HttpServerError, either a request-level error or a response-level error.

Signature

type HttpServerErrorReason = RequestError | ResponseError

Source

Since v4.0.0

Error describing an unexpected server-side failure while handling a request.

Details

When converted to a response it produces an empty 500 response.

Signature

declare class InternalError

Source

Since v4.0.0

Converts the server error into a 500 Internal Server Error response.

Signature

declare const [Respondable.symbol]: () => Effect.Effect<Response.HttpServerResponse, never, never>

Source

Since v4.0.0

Union of errors that are tied directly to an incoming server request.

Signature

type RequestError = RequestParseError | RouteNotFound | InternalError

Source

Since v4.0.0

Error describing a failure to parse or read an incoming request.

Details

When converted to a response it produces an empty 400 response.

Signature

declare class RequestParseError

Source

Since v4.0.0

Converts the request error into a 400 Bad Request response.

Signature

declare const [Respondable.symbol]: () => Effect.Effect<Response.HttpServerResponse, never, never>

Source

Since v4.0.0

Error describing a failure related to an HTTP response.

Details

It carries the request and response involved in the failure. When converted to a response it produces an empty 500 response.

Signature

declare class ResponseError

Source

Since v4.0.0

Signature

declare const [Respondable.symbol]: () => Effect.Effect<Response.HttpServerResponse, never, never>

Source

Error indicating that no route matched the incoming request.

Details

When converted to a response it produces an empty 404 response, and it is ignored by the error reporter.

Signature

declare class RouteNotFound

Source

Since v4.0.0

Signature

declare const [Respondable.symbol]: () => Effect.Effect<Response.HttpServerResponse, never, never>

Source

Signature

readonly [ErrorReporter.ignore]: true

Source

Error wrapping a low-level failure from the HTTP server implementation.

Signature

declare class ServeError

Source

Since v4.0.0

Returns true when the supplied value is an HttpServerError.

Signature

declare const isHttpServerError: (u: unknown) => u is HttpServerError

Source

Since v4.0.0