Go to Latest
function isClientErrorStatus
import { isClientErrorStatus } from "https://dotland.deno.dev/std@0.152.0/http/mod.ts";

A type guard that determines if the status code is a client error.

import isClientErrorStatus
import { isClientErrorStatus } from "https://dotland.deno.dev/std@0.152.0/http/mod.ts";

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.

Examples

import { errors, isHttpError } from "https://deno.land/std@0.152.0/http/http_errors.ts";

try {
  throw new errors.NotFound();
} catch (e) {
  if (isHttpError(e)) {
    const response = new Response(e.message, { status: e.status });
  } else {
    throw e;
  }
}
import { createHttpError } from "https://deno.land/std@0.152.0/http/http_errors.ts";
import { Status } from "https://deno.land/std@0.152.0/http/http_status.ts";

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