UNPKG

@sleekify/sleekify

Version:

A TypeScript decorator driven approach for developing web applications.

472 lines (471 loc) 17.2 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.NetworkAuthenticationRequiredError = exports.NotExtendedError = exports.LoopDetectedError = exports.InsufficientStorageError = exports.VariantAlsoNegotiatesError = exports.HTTPVersionNotSupportedError = exports.GatewayTimeoutError = exports.ServiceUnavailableError = exports.BadGatewayError = exports.NotImplementedError = exports.InternalServerError = exports.ServerWebApplicationError = exports.UnavailableForLegalReasonsError = exports.RequestHeaderFieldsTooLargeError = exports.TooManyRequestsError = exports.PreconditionRequiredError = exports.UpgradeRequiredError = exports.TooEarlyError = exports.FailedDependencyError = exports.LockedError = exports.UnprocessableContentError = exports.MisdirectedRequestError = exports.IAmATeapotError = exports.ExpectationFailedError = exports.RangeNotSatisfiableError = exports.UnsupportedMediaTypeError = exports.URITooLongError = exports.PayloadTooLargeError = exports.PreconditionFailedError = exports.LengthRequiredError = exports.GoneError = exports.ConflictError = exports.RequestTimeoutError = exports.ProxyAuthenticationRequiredError = exports.NotAcceptableError = exports.MethodNotAllowedError = exports.NotFoundError = exports.ForbiddenError = exports.PaymentRequiredError = exports.UnauthorizedError = exports.BadRequestError = exports.ClientWebApplicationError = exports.WebApplicationError = void 0; ; /** * The base class for all HTTP errors. */ class WebApplicationError extends Error { static reasonMap = {}; statusCode; constructor(status, message, options) { super(message, options); this.statusCode = status; } get status() { return this.statusCode; } get reason() { let reason = WebApplicationError.reasonMap[this.statusCode]; if (reason === undefined) { reason = this.constructor.name .replace('Error', '') .replace(/([a-z])([A-Z])/g, '$1 $2') .replace(/([A-Z])([A-Z][a-z])/g, '$1 $2'); WebApplicationError.reasonMap[this.statusCode] = reason; } return reason; } } exports.WebApplicationError = WebApplicationError; /** * The base class for all HTTP 4XX errors which indicate the client's request * is invalid and cause the error. */ class ClientWebApplicationError extends WebApplicationError { } exports.ClientWebApplicationError = ClientWebApplicationError; /** * HTTP 400 - The server cannot or will not process the request due to an * apparent client error (e.g., malformed request syntax, size too large, * invalid request message framing, or deceptive request routing). */ class BadRequestError extends ClientWebApplicationError { constructor(message, options) { super(400, message); } } exports.BadRequestError = BadRequestError; /** * HTTP 401 - Similar to 403 Forbidden, but specifically for use when * authentication is required and has failed or has not yet been provided. The * response must include a WWW-Authenticate header field containing a challenge * applicable to the requested resource. */ class UnauthorizedError extends ClientWebApplicationError { constructor(message, options) { super(401, message); } } exports.UnauthorizedError = UnauthorizedError; /** * HTTP 402 - Reserved for future use. The original intention was that this * code might be used as part of some form of digital cash or micropayment * scheme, as proposed, for example, but that has not yet happened, and this * code is not widely used. */ class PaymentRequiredError extends ClientWebApplicationError { constructor(message, options) { super(402, message); } } exports.PaymentRequiredError = PaymentRequiredError; /** * HTTP 403 - The request contained valid data and was understood by the * server, but the server is refusing action. This may be due to the user not * having the necessary permissions for a resource or needing an account of * some sort, or attempting a prohibited action. */ class ForbiddenError extends ClientWebApplicationError { constructor(message, options) { super(403, message); } } exports.ForbiddenError = ForbiddenError; /** * HTTP 404 - The requested resource could not be found but may be available in * the future. Subsequent requests by the client are permissible. */ class NotFoundError extends ClientWebApplicationError { constructor(message, options) { super(404, message); } } exports.NotFoundError = NotFoundError; /** * HTTP 405 - A request method is not supported for the requested resource; for * example, a GET request on a form that requires data to be presented via * POST, or a PUT request on a read-only resource. */ class MethodNotAllowedError extends ClientWebApplicationError { constructor(message, options) { super(405, message); } } exports.MethodNotAllowedError = MethodNotAllowedError; /** * HTTP 406 - The requested resource is capable of generating only content not * acceptable according to the Accept headers sent in the request. */ class NotAcceptableError extends ClientWebApplicationError { constructor(message, options) { super(406, message); } } exports.NotAcceptableError = NotAcceptableError; /** * HTTP 407 - The client must first authenticate itself with the proxy. */ class ProxyAuthenticationRequiredError extends ClientWebApplicationError { constructor(message, options) { super(407, message); } } exports.ProxyAuthenticationRequiredError = ProxyAuthenticationRequiredError; /** * HTTP 408 - The server timed out waiting for the request. According to HTTP * specifications: "The client did not produce a request within the time that * the server was prepared to wait. The client MAY repeat the request without * modifications at any later time." */ class RequestTimeoutError extends ClientWebApplicationError { constructor(message, options) { super(408, message); } } exports.RequestTimeoutError = RequestTimeoutError; /** * HTTP 409 - Indicates that the request could not be processed because of * conflict in the current state of the resource, such as an edit conflict * between multiple simultaneous updates. */ class ConflictError extends ClientWebApplicationError { constructor(message, options) { super(409, message); } } exports.ConflictError = ConflictError; /** * HTTP 410 - Indicates that the resource requested was previously in use but * is no longer available and will not be available again. This should be used * when a resource has been intentionally removed and the resource should be * purged. */ class GoneError extends ClientWebApplicationError { constructor(message, options) { super(410, message); } } exports.GoneError = GoneError; /** * HTTP 411 - The request did not specify the length of its content, which is * required by the requested resource. */ class LengthRequiredError extends ClientWebApplicationError { constructor(message, options) { super(411, message); } } exports.LengthRequiredError = LengthRequiredError; /** * HTTP 412 - The server does not meet one of the preconditions that the * requester put on the request header fields. */ class PreconditionFailedError extends ClientWebApplicationError { constructor(message, options) { super(412, message); } } exports.PreconditionFailedError = PreconditionFailedError; /** * HTTP 413 - The request is larger than the server is willing or able to * process. Previously called "Request Entity Too Large". */ class PayloadTooLargeError extends ClientWebApplicationError { constructor(message, options) { super(413, message); } } exports.PayloadTooLargeError = PayloadTooLargeError; /** * HTTP 414 - The URI provided was too long for the server to process. Often * the result of too much data being encoded as a query-string of a GET * request, in which case it should be converted to a POST request. */ class URITooLongError extends ClientWebApplicationError { constructor(message, options) { super(414, message); } } exports.URITooLongError = URITooLongError; /** * HTTP 415 - The request entity has a media type which the server or resource * does not support. For example, the client uploads an image as image/svg+xml, * but the server requires that images use a different format. */ class UnsupportedMediaTypeError extends ClientWebApplicationError { constructor(message, options) { super(415, message); } } exports.UnsupportedMediaTypeError = UnsupportedMediaTypeError; /** * HTTP 416 - The client has asked for a portion of the file (byte serving), * but the server cannot supply that portion. */ class RangeNotSatisfiableError extends ClientWebApplicationError { constructor(message, options) { super(416, message); } } exports.RangeNotSatisfiableError = RangeNotSatisfiableError; /** * HTTP 417 - The server cannot meet the requirements of the Expect * request-header field. */ class ExpectationFailedError extends ClientWebApplicationError { constructor(message, options) { super(417, message); } } exports.ExpectationFailedError = ExpectationFailedError; /** * HTTP 418 - This code was defined in 1998 as one of the traditional IETF * April Fools' jokes, in RFC 2324, Hyper Text Coffee Pot Control Protocol, and * is not expected to be implemented by actual HTTP servers. The RFC specifies * this code should be returned by teapots requested to brew coffee. */ class IAmATeapotError extends ClientWebApplicationError { reasonString = "I'm a Teapot"; constructor(message, options) { super(418, message); } get reason() { return this.reasonString; } } exports.IAmATeapotError = IAmATeapotError; /** * HTTP 421 - The request was directed at a server that is not able to produce * a response (for example because of connection reuse). */ class MisdirectedRequestError extends ClientWebApplicationError { constructor(message, options) { super(421, message); } } exports.MisdirectedRequestError = MisdirectedRequestError; /** * HTTP 422 - The request was well-formed (i.e., syntactically correct) but * could not be processed. */ class UnprocessableContentError extends ClientWebApplicationError { constructor(message, options) { super(422, message); } } exports.UnprocessableContentError = UnprocessableContentError; /** * HTTP 423 - The resource that is being accessed is locked. */ class LockedError extends ClientWebApplicationError { constructor(message, options) { super(423, message); } } exports.LockedError = LockedError; /** * HTTP 424 - The request failed because it depended on another request and * that request failed */ class FailedDependencyError extends ClientWebApplicationError { constructor(message, options) { super(424, message); } } exports.FailedDependencyError = FailedDependencyError; /** * HTTP 425 - Indicates that the server is unwilling to risk processing a * request that might be replayed. */ class TooEarlyError extends ClientWebApplicationError { constructor(message, options) { super(425, message); } } exports.TooEarlyError = TooEarlyError; /** * HTTP 426 - The client should switch to a different protocol such as TLS/1.3, * given in the Upgrade header field. */ class UpgradeRequiredError extends ClientWebApplicationError { constructor(message, options) { super(426, message); } } exports.UpgradeRequiredError = UpgradeRequiredError; /** * HTTP 428 - The origin server requires the request to be conditional. * Intended to prevent the 'lost update' problem, where a client GETs a * resource's state, modifies it, and PUTs it back to the server, when * meanwhile a third party has modified the state on the server, leading to a * conflict. */ class PreconditionRequiredError extends ClientWebApplicationError { constructor(message, options) { super(428, message); } } exports.PreconditionRequiredError = PreconditionRequiredError; /** * HTTP 429 - The user has sent too many requests in a given amount of time. * Intended for use with rate-limiting schemes. */ class TooManyRequestsError extends ClientWebApplicationError { constructor(message, options) { super(429, message); } } exports.TooManyRequestsError = TooManyRequestsError; /** * HTTP 431 - The server is unwilling to process the request because either an * individual header field, or all the header fields collectively, are too * large. */ class RequestHeaderFieldsTooLargeError extends ClientWebApplicationError { constructor(message, options) { super(431, message); } } exports.RequestHeaderFieldsTooLargeError = RequestHeaderFieldsTooLargeError; /** * HTTP 451 - A server operator has received a legal demand to deny access to a * resource or to a set of resources that includes the requested resource. */ class UnavailableForLegalReasonsError extends ClientWebApplicationError { constructor(message, options) { super(451, message); } } exports.UnavailableForLegalReasonsError = UnavailableForLegalReasonsError; /** * The base class for all HTTP 5XX errors which indicate the server encoutered * a non-recoverable error. */ class ServerWebApplicationError extends WebApplicationError { } exports.ServerWebApplicationError = ServerWebApplicationError; /** * HTTP 500 - A generic error message, given when an unexpected condition was * encountered and no more specific message is suitable. */ class InternalServerError extends ServerWebApplicationError { reasonString = 'Internal Server Error'; constructor(message, options) { super(500, message); } get reason() { return this.reasonString; } } exports.InternalServerError = InternalServerError; /** * HTTP 501 - The server either does not recognize the request method, or it * lacks the ability to fulfil the request. Usually this implies future * availability (e.g., a new feature of a web-service API). */ class NotImplementedError extends ServerWebApplicationError { constructor(message, options) { super(501, message); } } exports.NotImplementedError = NotImplementedError; /** * HTTP 502 - The server was acting as a gateway or proxy and received an * invalid response from the upstream server. */ class BadGatewayError extends ServerWebApplicationError { constructor(message, options) { super(502, message); } } exports.BadGatewayError = BadGatewayError; /** * HTTP 503 - The server cannot handle the request (because it is overloaded or * down for maintenance). Generally, this is a temporary state. */ class ServiceUnavailableError extends ServerWebApplicationError { constructor(message, options) { super(503, message); } } exports.ServiceUnavailableError = ServiceUnavailableError; /** * HTTP 504 - The server was acting as a gateway or proxy and did not receive a * timely response from the upstream server. */ class GatewayTimeoutError extends ServerWebApplicationError { constructor(message, options) { super(504, message); } } exports.GatewayTimeoutError = GatewayTimeoutError; /** * HTTP 505 - The server does not support the HTTP version used in the request. */ class HTTPVersionNotSupportedError extends ServerWebApplicationError { constructor(message, options) { super(505, message); } } exports.HTTPVersionNotSupportedError = HTTPVersionNotSupportedError; /** * HTTP 506 - Transparent content negotiation for the request results in a * circular reference. */ class VariantAlsoNegotiatesError extends ServerWebApplicationError { constructor(message, options) { super(506, message); } } exports.VariantAlsoNegotiatesError = VariantAlsoNegotiatesError; /** * HTTP 507 - The server is unable to store the representation needed to * complete the request. */ class InsufficientStorageError extends ServerWebApplicationError { constructor(message, options) { super(507, message); } } exports.InsufficientStorageError = InsufficientStorageError; /** * HTTP 508 - The server detected an infinite loop while processing the * request. */ class LoopDetectedError extends ServerWebApplicationError { constructor(message, options) { super(508, message); } } exports.LoopDetectedError = LoopDetectedError; /** * HTTP 510 - Further extensions to the request are required for the server to * fulfil it. */ class NotExtendedError extends ServerWebApplicationError { constructor(message, options) { super(510, message); } } exports.NotExtendedError = NotExtendedError; /** * HTTP 511 - The client needs to authenticate to gain network access. Intended * for use by intercepting proxies used to control access to the network. */ class NetworkAuthenticationRequiredError extends ServerWebApplicationError { constructor(message, options) { super(511, message); } } exports.NetworkAuthenticationRequiredError = NetworkAuthenticationRequiredError;