Skip to main content
Module

x/keywork/mod.ts>HTTP.ErrorResponse

A library for building V8 Isolate web apps on Cloudflare Workers, Deno, and Node.JS
Go to Latest
class HTTP.ErrorResponse
Re-export
import { HTTP } from "https://deno.land/x/keywork@v6.0.1/mod.ts";
const { ErrorResponse } = HTTP;

An error response sent to a client when a request is deemed to be invalid in some way.

Constructors

new
ErrorResponse(
errorLike: unknown,
publicReason?: string,
headersInit?: HeadersInit,
)

Given an error-like object, attempt to respond with a KeyworkResourceError.

try {
  result = await fetchFoobarResource()
} catch (error) {
  // Log the error internally...
  logger.error(error)

  // And then respond with a public reason...
  return new ErrorResponse(error, 'An error occured while fetching foobar.')
}
new
ErrorResponse(
status?: Status,
statusText?: string,
body?: BodyInit | null,
headersInit?: HeadersInit,
)

Given an invalid request that goes against your application logic, construct a custom error response.

new
ErrorResponse(...args: any[])