import { KeyworkResourceError } from "https://deno.land/x/keywork@v5.0.3/errors/KeyworkResourceError.ts";
An error class that feels fits nicely into an incoming HTTP request handler.
Examples
Example 1
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
Properties
status: Status
The HTTP Status Code associated with the error.
Static Methods
assertIsConstructorOf(ErrorCtor: unknown): ErrorCtor is KeyworkResourceError
assertIsInstanceOf(errorLike: Error): errorLike is KeyworkResourceError