UNPKG

shelving

Version:

Toolkit for using data in JavaScript.

43 lines (42 loc) 1.72 kB
import { BaseError } from "./BaseError.js"; /** Error thrown when a request isn't well-formed. */ export class RequestError extends BaseError { /** The corresponding HTTP status code for this error, in the range `400-499` */ code = 400; constructor(message, options) { super(message, { caller: RequestError, ...options }); } } RequestError.prototype.name = "RequestError"; /** Thrown if an operation failed because the user is not logged in, or the login information is not well-formed. */ export class UnauthorizedError extends RequestError { code = 401; constructor(message, options) { super(message, { caller: UnauthorizedError, ...options }); } } UnauthorizedError.prototype.name = "UnauthorizedError"; /** Thrown if the requested content is not found. */ export class NotFoundError extends RequestError { code = 404; constructor(message, options) { super(message, { caller: NotFoundError, ...options }); } } NotFoundError.prototype.name = "NotFoundError"; /** Error thrown when a request is is valid and well-formed, but its actual data is not. */ export class UnprocessableError extends RequestError { code = 422; constructor(message, options) { super(message, { caller: UnprocessableError, ...options }); } } UnprocessableError.prototype.name = "UnprocessableError"; /** Thrown if an operation failed because the user is logged in, but does not have sufficient privileges to access this content. */ export class ForbiddenError extends RequestError { code = 403; constructor(message, options) { super(message, { caller: ForbiddenError, ...options }); } } ForbiddenError.prototype.name = "ForbiddenError";