HttpServerError.ts
HttpServerError.ts overview
Section titled “HttpServerError.ts overview”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
Exports Grouped by Category
Section titled “Exports Grouped by Category”- annotations
- error handling
- errors
- predicates
annotations
Section titled “annotations”ClientAbort (class)
Section titled “ClientAbort (class)”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 ClientAbortSince v4.0.0
error handling
Section titled “error handling”causeResponse
Section titled “causeResponse”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>]>Since v4.0.0
causeResponseStripped
Section titled “causeResponseStripped”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>>]Since v4.0.0
exitResponse
Section titled “exitResponse”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.HttpServerResponseSince v4.0.0
errors
Section titled “errors”HttpServerError (class)
Section titled “HttpServerError (class)”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 })}Since v4.0.0
[Respondable.symbol] (method)
Section titled “[Respondable.symbol] (method)”Signature
declare const [Respondable.symbol]: () => Effect.Effect<Response.HttpServerResponse, never, never>[TypeId] (property)
Section titled “[TypeId] (property)”Signature
readonly [TypeId]: "~effect/http/HttpServerError"stack (property)
Section titled “stack (property)”Signature
stack: stringHttpServerErrorReason (type alias)
Section titled “HttpServerErrorReason (type alias)”Reason carried by an HttpServerError, either a request-level error or a response-level error.
Signature
type HttpServerErrorReason = RequestError | ResponseErrorSince v4.0.0
InternalError (class)
Section titled “InternalError (class)”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 InternalErrorSince v4.0.0
[Respondable.symbol] (method)
Section titled “[Respondable.symbol] (method)”Converts the server error into a 500 Internal Server Error response.
Signature
declare const [Respondable.symbol]: () => Effect.Effect<Response.HttpServerResponse, never, never>Since v4.0.0
RequestError (type alias)
Section titled “RequestError (type alias)”Union of errors that are tied directly to an incoming server request.
Signature
type RequestError = RequestParseError | RouteNotFound | InternalErrorSince v4.0.0
RequestParseError (class)
Section titled “RequestParseError (class)”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 RequestParseErrorSince v4.0.0
[Respondable.symbol] (method)
Section titled “[Respondable.symbol] (method)”Converts the request error into a 400 Bad Request response.
Signature
declare const [Respondable.symbol]: () => Effect.Effect<Response.HttpServerResponse, never, never>Since v4.0.0
ResponseError (class)
Section titled “ResponseError (class)”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 ResponseErrorSince v4.0.0
[Respondable.symbol] (method)
Section titled “[Respondable.symbol] (method)”Signature
declare const [Respondable.symbol]: () => Effect.Effect<Response.HttpServerResponse, never, never>RouteNotFound (class)
Section titled “RouteNotFound (class)”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 RouteNotFoundSince v4.0.0
[Respondable.symbol] (method)
Section titled “[Respondable.symbol] (method)”Signature
declare const [Respondable.symbol]: () => Effect.Effect<Response.HttpServerResponse, never, never>[ErrorReporter.ignore] (property)
Section titled “[ErrorReporter.ignore] (property)”Signature
readonly [ErrorReporter.ignore]: trueServeError (class)
Section titled “ServeError (class)”Error wrapping a low-level failure from the HTTP server implementation.
Signature
declare class ServeErrorSince v4.0.0
predicates
Section titled “predicates”isHttpServerError
Section titled “isHttpServerError”Returns true when the supplied value is an HttpServerError.
Signature
declare const isHttpServerError: (u: unknown) => u is HttpServerErrorSince v4.0.0