Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Error List

All error classes are exported from resource-machine and extend HttpError.

import { BadRequestError, NotFoundError } from "resource-machine";

Every error has:

  • statusCode: number — the HTTP status code
  • body: { code: string; message: string } — the JSON response body
  • message: string — the error message (same as body.message)

HTTP Error Classes

StatusClass
400BadRequestError
401UnauthorizedError
403ForbiddenError
404NotFoundError
405MethodNotAllowedError
406NotAcceptableError
409ConflictError
410GoneError
412PreconditionFailedError
413PayloadTooLargeError
414UriTooLongError
415UnsupportedMediaTypeError
500InternalServerError
501NotImplementedError
503ServiceUnavailableError

Base Class

import { HttpError } from "resource-machine";

// All of the above extend HttpError
class HttpError extends Error {
	readonly statusCode: number;
	readonly body: { code: string; message: string };
}