Skip to main content


Deno standard library
Go to Latest
import * as mod from "";

A collection of HTTP errors and utilities.

The export errors contains an individual class that extends HttpError which makes handling HTTP errors in a structured way.

The function createHttpError provides a way to create instances of errors in a factory pattern.

The function isHttpError is a type guard that will narrow a value to an HttpError instance.


Example 1

import { errors, isHttpError } from "";

try {
  throw new errors.NotFound();
} catch (e) {
  if (isHttpError(e)) {
    const response = new Response(e.message, { status: e.status });
  } else {
    throw e;

Example 2

import { createHttpError } from "";
import { Status } from "";

try {
  throw createHttpError(
    "The request was bad.",
    { expose: false }
} catch (e) {
  // handle errors


The base class that all derivative HTTP extend, providing a status and an expose property.


A namespace that contains each error constructor. Each error extends HTTPError and provides .status and .expose properties, where the .status will be an error Status value and .expose indicates if information, like a stack trace, should be shared in the response.


A factory function which provides a way to create errors. It takes up to 3 arguments, the error Status, an message, which defaults to the status text and error options, which includes the expose property to set the .expose value on the error.

A type guard that determines if the value is an HttpError or not.