Skip to main content
Using Deno in production at your company? Earn free Deno merch.
Give us feedback
Module

x/keywork/errors/mod.ts>KeyworkResourceError

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

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

Examples

Example 1

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