Module

x/drash/src/modules/chains/RequestChain/mod.native.ts>HTTPError

A microframework for building JavaScript HTTP applications. Runtime-agnostic. Strongly typed.
Latest
class HTTPError
extends Error
import { HTTPError } from "https://dotland.deno.dev/x/drash@v3.0.0-beta.2/src/modules/chains/RequestChain/mod.native.ts";

Base class for all HTTP errors in Drash. Use this class to throw uniform HTTP errors.

Examples

Example 1

// Usage in resource's GET method

class MyResource extends Resource {
  public GET(request: Request) {
    if (!request.header("authorization")) {
      throw new HTTPError(401, "Get out!");
    }

    return new Response("Authed");
  }
}

Constructors

new
HTTPError(status: ResponseStatus, message?: string)

Properties

readonly
name: string

The name of this error to be used with conditionals that do not work with instanceof.

readonly
status_code: ResponseStatusCode

The HTTP status code associated with this error.

readonly
status_code_description: string