Skip to main content

KeyworkResourceError

Overview

An error class that feels fits nicely into an incoming HTTP request handler.

import { KeyworkResourceError, StatusCodes } from 'keywork/errors'

if (isLoggedIn(someUser)) {
throw new KeyworkResourceError("You must be logged in to do that", StatusCodes.UNAUTHORIZED)
}

if (someUser.role !== 'admin') {
throw new KeyworkResourceError("Only an admin can access that", StatusCodes.FORBIDDEN)
}

Usage

import { KeyworkResourceError } from 'keywork/errors'

Hierarchy

  • Error

    KeyworkResourceError

Constructors

constructor

new KeyworkResourceError

(statusText?, status?)

Parameters in the format of an HTTP status error.

Parameters

NameTypeDescription
statusText?stringDefault Value STATUS_TEXT[Status.InternalServerError] See Re-exported from https://deno.land/[email protected]/http/http_status.ts
status?StatusDefault Value Status.InternalServerError See Re-exported from https://deno.land/[email protected]/http/http_status.ts

Overrides

Error.constructor

Defined in

errors/KeyworkResourceError.ts:57

new KeyworkResourceError

(errorLike)

Deprecated

TypeScript has inferred that errorLike is already an instance of KeyworkResourceError

Parameters

NameType
errorLikeKeyworkResourceError

Overrides

Error.constructor

Defined in

errors/KeyworkResourceError.ts:74

new KeyworkResourceError

(errorLike, status?)

Converting an unknown error object into a well-formed KeyworkResourceError

Parameters

NameTypeDescription
errorLikeunknown
status?StatusDefault Value Status.InternalServerError See Re-exported from https://deno.land/[email protected]/http/http_status.ts

Overrides

Error.constructor

Defined in

errors/KeyworkResourceError.ts:78

Properties

status

status: [`Status`](../enums/Status.mdx)

The HTTP Status Code associated with the error.

Defined in

errors/KeyworkResourceError.ts:52

statusText

statusText: `string`

The reason for the error.

Defined in

errors/KeyworkResourceError.ts:48

Accessors

message

get message

(): `string`

Returns

string

Overrides

Error.message

Defined in

errors/KeyworkResourceError.ts:109

Methods

toJSON

toJSON

(): [`ErrorJSONBody`](../interfaces/ErrorJSONBody.mdx)

Returns

ErrorJSONBody

Defined in

errors/KeyworkResourceError.ts:113

assertIsConstructorOf

Static assertIsConstructorOf

(ErrorCtor): ErrorCtor is typeof KeyworkResourceError

Parameters

NameType
ErrorCtorunknown

Returns

ErrorCtor is typeof KeyworkResourceError

Defined in

errors/KeyworkResourceError.ts:133

assertIsInstanceOf

Static assertIsInstanceOf

(errorLike): errorLike is KeyworkResourceError

Parameters

NameType
errorLikeError

Returns

errorLike is KeyworkResourceError

Defined in

errors/KeyworkResourceError.ts:127