ErrorResponse
Overview
Usage
- Node
- Deno
- Browser/ESM
import { ErrorResponse } from 'keywork/http/classes'
import { ErrorResponse } from 'https://deno.land/x/keywork/http/classes'
let { ErrorResponse } = await import('https://esm.sh/keywork/http/classes')
Hierarchy
Response
↳
ErrorResponse
Constructors
constructor
new ErrorResponse
(errorLike, publicReason?, 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.')
}
Parameters
Name | Type | Description |
---|---|---|
errorLike | unknown | |
publicReason? | string | |
headersInit? | HeadersInit |
Overrides
Response.constructor
Defined in
http/classes/ErrorResponse.ts:39
new ErrorResponse
(status?, statusText?, body?, headersInit?)
Given an invalid request that goes against your application logic, construct a custom error response.
Parameters
Name | Type | Description |
---|---|---|
status? | Status | |
statusText? | string | |
body? | null | BodyInit |
headersInit? | HeadersInit |
Overrides
Response.constructor
Defined in
http/classes/ErrorResponse.ts:53
An error response sent to a client when a request is deemed to be invalid in some way.