Skip to main content

ErrorResponse

Overview

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

Usage

import { ErrorResponse } from '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

NameTypeDescription
errorLikeunknown
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

NameTypeDescription
status?Status
statusText?string
body?nullBodyInit
headersInit?HeadersInit

Overrides

Response.constructor

Defined in

http/classes/ErrorResponse.ts:53