std/http/mod.ts

Deno standard library
Go to Latest
enum Status
import { Status } from "https://deno.land/std@0.147.0/http/mod.ts?s=Status";

Standard HTTP status codes.

Members

Accepted = 202[src]

RFC 7231, 6.3.3

AlreadyReported = 208[src]

RFC 5842, 7.1

BadGateway = 502[src]

RFC 7231, 6.6.3

BadRequest = 400[src]

RFC 7231, 6.5.1

Conflict = 409[src]

RFC 7231, 6.5.8

Continue = 100[src]

RFC 7231, 6.2.1

Created = 201[src]

RFC 7231, 6.3.2

EarlyHints = 103[src]

RFC 8297 *

ExpectationFailed = 417[src]

RFC 7231, 6.5.14

FailedDependency = 424[src]

RFC 4918, 11.4

Forbidden = 403[src]

RFC 7231, 6.5.3

Found = 302[src]

RFC 7231, 6.4.3

GatewayTimeout = 504[src]

RFC 7231, 6.6.5

Gone = 410[src]

RFC 7231, 6.5.9

HTTPVersionNotSupported = 505[src]

RFC 7231, 6.6.6

IMUsed = 226[src]

RFC 3229, 10.4.1

InsufficientStorage = 507[src]

RFC 4918, 11.5

InternalServerError = 500[src]

RFC 7231, 6.6.1

LengthRequired = 411[src]

RFC 7231, 6.5.10

Locked = 423[src]

RFC 4918, 11.3

LoopDetected = 508[src]

RFC 5842, 7.2

MethodNotAllowed = 405[src]

RFC 7231, 6.5.5

MisdirectedRequest = 421[src]

RFC 7540, 9.1.2

MovedPermanently = 301[src]

RFC 7231, 6.4.2

MultipleChoices = 300[src]

RFC 7231, 6.4.1

MultiStatus = 207[src]

RFC 4918, 11.1

NetworkAuthenticationRequired = 511[src]

RFC 6585, 6

NoContent = 204[src]

RFC 7231, 6.3.5

NonAuthoritativeInfo = 203[src]

RFC 7231, 6.3.4

NotAcceptable = 406[src]

RFC 7231, 6.5.6

NotExtended = 510[src]

RFC 2774, 7

NotFound = 404[src]

RFC 7231, 6.5.4

NotImplemented = 501[src]

RFC 7231, 6.6.2

NotModified = 304[src]

RFC 7232, 4.1

OK = 200[src]

RFC 7231, 6.3.1

PartialContent = 206[src]

RFC 7233, 4.1

PaymentRequired = 402[src]

RFC 7231, 6.5.2

PermanentRedirect = 308[src]

RFC 7538, 3

PreconditionFailed = 412[src]

RFC 7232, 4.2

PreconditionRequired = 428[src]

RFC 6585, 3

Processing = 102[src]

RFC 2518, 10.1

ProxyAuthRequired = 407[src]

RFC 7235, 3.2

RequestedRangeNotSatisfiable = 416[src]

RFC 7233, 4.4

RequestEntityTooLarge = 413[src]

RFC 7231, 6.5.11

RequestHeaderFieldsTooLarge = 431[src]

RFC 6585, 5

RequestTimeout = 408[src]

RFC 7231, 6.5.7

RequestURITooLong = 414[src]

RFC 7231, 6.5.12

ResetContent = 205[src]

RFC 7231, 6.3.6

SeeOther = 303[src]

RFC 7231, 6.4.4

ServiceUnavailable = 503[src]

RFC 7231, 6.6.4

SwitchingProtocols = 101[src]

RFC 7231, 6.2.2

Teapot = 418[src]

RFC 7168, 2.3.3

TemporaryRedirect = 307[src]

RFC 7231, 6.4.7

TooEarly = 425[src]

RFC 8470, 5.2

TooManyRequests = 429[src]

RFC 6585, 4

Unauthorized = 401[src]

RFC 7235, 3.1

UnavailableForLegalReasons = 451[src]

RFC 7725, 3

UnprocessableEntity = 422[src]

RFC 4918, 11.2

UnsupportedMediaType = 415[src]

RFC 7231, 6.5.13

UpgradeRequired = 426[src]

RFC 7231, 6.5.15

UseProxy = 305[src]

RFC 7231, 6.4.5

VariantAlsoNegotiates = 506[src]

RFC 2295, 8.1

import Status
import { Status } from "https://deno.land/std@0.147.0/http/mod.ts?s=Status";

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.147.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.147.0/http/http_errors.ts";
import { Status } from "https://deno.land/std@0.147.0/http/http_status.ts";

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