Skip to main content
Module

x/keywork/mod.ts>Errors.KeyworkResourceError

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

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)
}

Constructors

new
KeyworkResourceError(statusText?: string, status?: Status)

Parameters in the format of an HTTP status error.

new
KeyworkResourceError(errorLike: KeyworkResourceError)
new
KeyworkResourceError(errorLike: unknown, status?: Status)

Converting an unknown error object into a well-formed KeyworkResourceError

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

Properties

readonly
message
status: Status

The HTTP Status Code associated with the error.

statusText: string

The reason for the error.

readonly
[$ClassID]

Static Properties

readonly
[$ClassID]

Static Methods

assertIsConstructorOf(ErrorCtor: unknown): ErrorCtor is KeyworkResourceError
assertIsInstanceOf(errorLike: Error): errorLike is KeyworkResourceError