Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

x/keywork/http/mod.ts>ErrorResponse

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

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[])