UNPKG

http-response-status-code

Version:

A lightweight utility for retrieving HTTP status codes, names, and descriptions. Easily validate, categorize, and manage HTTP responses with built-in methods for informational, success, redirection, client, and server error codes.

502 lines (501 loc) 19.5 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.GONE = exports.CONFLICT = exports.REQUEST_TIMEOUT = exports.PROXY_AUTHENTICATION_REQUIRED = exports.NOT_ACCEPTABLE = exports.METHOD_NOT_ALLOWED = exports.NOT_FOUND = exports.FORBIDDEN = exports.PAYMENT_REQUIRED = exports.UNAUTHORIZED = exports.BAD_REQUEST = exports.PERMANENT_REDIRECT = exports.TEMPORARY_REDIRECT = exports.SWITCH_PROXY = exports.USE_PROXY = exports.NOT_MODIFIED = exports.SEE_OTHER = exports.MOVED_TEMPORARILY = exports.MOVED_PERMANENTLY = exports.MULTIPLE_CHOICES = exports.IM_USED = exports.ALREADY_REPORTED = exports.MULTI_STATUS = exports.PARTIAL_CONTENT = exports.RESET_CONTENT = exports.NO_CONTENT = exports.NON_AUTHORITATIVE_INFORMATION = exports.ACCEPTED = exports.CREATED = exports.OK = exports.TOO_LONG = exports.EARLY_HINTS = exports.PROCESSING = exports.SWITCHING_PROTOCOLS = exports.CONTINUE = exports.isValidStatusCode = exports.getServerErrorCodes = exports.getClientErrorCodes = exports.getRedirectionalCodes = exports.getSuccessCodes = exports.getInformationalCodes = exports.isServerError = exports.isClientError = exports.isRedirectional = exports.isSuccess = exports.isInformational = exports.getStatusDescription = exports.getStatusName = exports.getStatusCode = exports.CODES = void 0; exports.NETWORK_AUTHENTICATION_REQUIRED = exports.NOT_EXTENDED = exports.LOOP_DETECTED = exports.INSUFFICIENT_STORAGE = exports.VARIANT_ALSO_NEGOTIATES = exports.HTTP_VERSION_NOT_SUPPORTED = exports.GATEWAY_TIMEOUT = exports.SERVICE_UNAVAILABLE = exports.BAD_GATEWAY = exports.NOT_IMPLEMENTED = exports.INTERNAL_SERVER_ERROR = exports.UNAVAILABLE_FOR_LEGAL_REASONS = exports.REQUEST_HEADER_FIELDS_TOO_LARGE = exports.TOO_MANY_REQUESTS = exports.PRECONDITION_REQUIRED = exports.UPGRADE_REQUIRED = exports.TOO_EARLY = exports.FAILED_DEPENDENCY = exports.LOCKED = exports.UNPROCESSABLE_ENTITY = exports.MISDIRECTED_REQUEST = exports.METHOD_FAILURE = exports.INSUFFICIENT_SPACE_ON_RESOURCE = exports.IM_A_TEAPOT = exports.EXPECTATION_FAILED = exports.REQUESTED_RANGE_NOT_SATISFIABLE = exports.UNSUPPORTED_MEDIA_TYPE = exports.REQUEST_URI_TOO_LONG = exports.REQUEST_TOO_LONG = exports.PRECONDITION_FAILED = exports.LENGTH_REQUIRED = void 0; var constants_1 = require("./constants"); Object.defineProperty(exports, "CODES", { enumerable: true, get: function () { return constants_1.CODES; } }); var utils_1 = require("./utils"); Object.defineProperty(exports, "getStatusCode", { enumerable: true, get: function () { return utils_1.getStatusCode; } }); Object.defineProperty(exports, "getStatusName", { enumerable: true, get: function () { return utils_1.getStatusName; } }); Object.defineProperty(exports, "getStatusDescription", { enumerable: true, get: function () { return utils_1.getStatusDescription; } }); Object.defineProperty(exports, "isInformational", { enumerable: true, get: function () { return utils_1.isInformational; } }); Object.defineProperty(exports, "isSuccess", { enumerable: true, get: function () { return utils_1.isSuccess; } }); Object.defineProperty(exports, "isRedirectional", { enumerable: true, get: function () { return utils_1.isRedirectional; } }); Object.defineProperty(exports, "isClientError", { enumerable: true, get: function () { return utils_1.isClientError; } }); Object.defineProperty(exports, "isServerError", { enumerable: true, get: function () { return utils_1.isServerError; } }); Object.defineProperty(exports, "getInformationalCodes", { enumerable: true, get: function () { return utils_1.getInformationalCodes; } }); Object.defineProperty(exports, "getSuccessCodes", { enumerable: true, get: function () { return utils_1.getSuccessCodes; } }); Object.defineProperty(exports, "getRedirectionalCodes", { enumerable: true, get: function () { return utils_1.getRedirectionalCodes; } }); Object.defineProperty(exports, "getClientErrorCodes", { enumerable: true, get: function () { return utils_1.getClientErrorCodes; } }); Object.defineProperty(exports, "getServerErrorCodes", { enumerable: true, get: function () { return utils_1.getServerErrorCodes; } }); Object.defineProperty(exports, "isValidStatusCode", { enumerable: true, get: function () { return utils_1.isValidStatusCode; } }); /** * HTTP status code for "Continue" (100). * * @constant {number} */ exports.CONTINUE = constants_1.HTTP_STATUS_MAPPINGS.CONTINUE.code; /** * HTTP status code for "Switching Protocols" (101). * * @constant {number} */ exports.SWITCHING_PROTOCOLS = constants_1.HTTP_STATUS_MAPPINGS.SWITCHING_PROTOCOLS.code; /** * HTTP status code for "Processing" (102). * * @constant {number} */ exports.PROCESSING = constants_1.HTTP_STATUS_MAPPINGS.PROCESSING.code; /** * HTTP status code for "Early Hints" (103). * * @constant {number} */ exports.EARLY_HINTS = constants_1.HTTP_STATUS_MAPPINGS.EARLY_HINTS.code; /** * HTTP status code for "Too Long" (122). * * @constant {number} */ exports.TOO_LONG = constants_1.HTTP_STATUS_MAPPINGS.TOO_LONG.code; /** * HTTP status code for "OK" (200). * * @constant {number} */ exports.OK = constants_1.HTTP_STATUS_MAPPINGS.OK.code; /** * HTTP status code for "Created" (201). * * @constant {number} */ exports.CREATED = constants_1.HTTP_STATUS_MAPPINGS.CREATED.code; /** * HTTP status code for "Accepted" (202). * * @constant {number} */ exports.ACCEPTED = constants_1.HTTP_STATUS_MAPPINGS.ACCEPTED.code; /** * HTTP status code for "Non Authoritative Information" (203). * * @constant {number} */ exports.NON_AUTHORITATIVE_INFORMATION = constants_1.HTTP_STATUS_MAPPINGS.NON_AUTHORITATIVE_INFORMATION.code; /** * HTTP status code for "No Content" (204). * * @constant {number} */ exports.NO_CONTENT = constants_1.HTTP_STATUS_MAPPINGS.NO_CONTENT.code; /** * HTTP status code for "Reset Content" (205). * * @constant {number} */ exports.RESET_CONTENT = constants_1.HTTP_STATUS_MAPPINGS.RESET_CONTENT.code; /** * HTTP status code for "Partial Content" (206). * * @constant {number} */ exports.PARTIAL_CONTENT = constants_1.HTTP_STATUS_MAPPINGS.PARTIAL_CONTENT.code; /** * HTTP status code for "Multi-Status" (207). * * @constant {number} */ exports.MULTI_STATUS = constants_1.HTTP_STATUS_MAPPINGS.MULTI_STATUS.code; /** * HTTP status code for "Already Reported" (208). * * @constant {number} */ exports.ALREADY_REPORTED = constants_1.HTTP_STATUS_MAPPINGS.ALREADY_REPORTED.code; /** * HTTP status code for "IM Used" (226). * * @constant {number} */ exports.IM_USED = constants_1.HTTP_STATUS_MAPPINGS.IM_USED.code; /** * HTTP status code for "Multiple Choices" (300). * * @constant {number} */ exports.MULTIPLE_CHOICES = constants_1.HTTP_STATUS_MAPPINGS.MULTIPLE_CHOICES.code; /** * HTTP status code for "Moved Permanently" (301). * * @constant {number} */ exports.MOVED_PERMANENTLY = constants_1.HTTP_STATUS_MAPPINGS.MOVED_PERMANENTLY.code; /** * HTTP status code for "Moved Temporarily" (302). * * @constant {number} */ exports.MOVED_TEMPORARILY = constants_1.HTTP_STATUS_MAPPINGS.MOVED_TEMPORARILY.code; /** * HTTP status code for "See Other" (303). * * @constant {number} */ exports.SEE_OTHER = constants_1.HTTP_STATUS_MAPPINGS.SEE_OTHER.code; /** * HTTP status code for "Not Modified" (304). * * @constant {number} */ exports.NOT_MODIFIED = constants_1.HTTP_STATUS_MAPPINGS.NOT_MODIFIED.code; /** * HTTP status code for "Use Proxy" (305). * * @constant {number} */ exports.USE_PROXY = constants_1.HTTP_STATUS_MAPPINGS.USE_PROXY.code; /** * HTTP status code for "Switch Proxy" (306). * * @constant {number} */ exports.SWITCH_PROXY = constants_1.HTTP_STATUS_MAPPINGS.SWITCH_PROXY.code; /** * HTTP status code for "Temporary Redirect" (307). * * @constant {number} */ exports.TEMPORARY_REDIRECT = constants_1.HTTP_STATUS_MAPPINGS.TEMPORARY_REDIRECT.code; /** * HTTP status code for "Permanent Redirect" (308). * * @constant {number} */ exports.PERMANENT_REDIRECT = constants_1.HTTP_STATUS_MAPPINGS.PERMANENT_REDIRECT.code; /** * HTTP status code for "Bad Request" (400). * * @constant {number} */ exports.BAD_REQUEST = constants_1.HTTP_STATUS_MAPPINGS.BAD_REQUEST.code; /** * HTTP status code for "Unauthorized" (401). * * @constant {number} */ exports.UNAUTHORIZED = constants_1.HTTP_STATUS_MAPPINGS.UNAUTHORIZED.code; /** * HTTP status code for "Payment Required" (402). * * @constant {number} */ exports.PAYMENT_REQUIRED = constants_1.HTTP_STATUS_MAPPINGS.PAYMENT_REQUIRED.code; /** * HTTP status code for "Forbidden" (403). * * @constant {number} */ exports.FORBIDDEN = constants_1.HTTP_STATUS_MAPPINGS.FORBIDDEN.code; /** * HTTP status code for "Not Found" (404). * * @constant {number} */ exports.NOT_FOUND = constants_1.HTTP_STATUS_MAPPINGS.NOT_FOUND.code; /** * HTTP status code for "Method Not Allowed" (405). * * @constant {number} */ exports.METHOD_NOT_ALLOWED = constants_1.HTTP_STATUS_MAPPINGS.METHOD_NOT_ALLOWED.code; /** * HTTP status code for "Not Acceptable" (406). * * @constant {number} */ exports.NOT_ACCEPTABLE = constants_1.HTTP_STATUS_MAPPINGS.NOT_ACCEPTABLE.code; /** * HTTP status code for "Proxy Authentication Required" (407). * * @constant {number} */ exports.PROXY_AUTHENTICATION_REQUIRED = constants_1.HTTP_STATUS_MAPPINGS.PROXY_AUTHENTICATION_REQUIRED.code; /** * HTTP status code for "Request Timeout" (408). * * @constant {number} */ exports.REQUEST_TIMEOUT = constants_1.HTTP_STATUS_MAPPINGS.REQUEST_TIMEOUT.code; /** * HTTP status code for "Conflict" (409). * * @constant {number} */ exports.CONFLICT = constants_1.HTTP_STATUS_MAPPINGS.CONFLICT.code; /** * HTTP status code for "Gone" (410). * * @constant {number} */ exports.GONE = constants_1.HTTP_STATUS_MAPPINGS.GONE.code; /** * HTTP status code for "Length Required" (411). * * @constant {number} */ exports.LENGTH_REQUIRED = constants_1.HTTP_STATUS_MAPPINGS.LENGTH_REQUIRED.code; /** * HTTP status code for "Precondition Failed" (412). * * @constant {number} */ exports.PRECONDITION_FAILED = constants_1.HTTP_STATUS_MAPPINGS.PRECONDITION_FAILED.code; /** * HTTP status code for "Request Entity Too Large" (413). * * @constant {number} */ exports.REQUEST_TOO_LONG = constants_1.HTTP_STATUS_MAPPINGS.REQUEST_TOO_LONG.code; /** * HTTP status code for "Request-URI Too Long" (414). * * @constant {number} */ exports.REQUEST_URI_TOO_LONG = constants_1.HTTP_STATUS_MAPPINGS.REQUEST_URI_TOO_LONG.code; /** * HTTP status code for "Unsupported Media Type" (415). * * @constant {number} */ exports.UNSUPPORTED_MEDIA_TYPE = constants_1.HTTP_STATUS_MAPPINGS.UNSUPPORTED_MEDIA_TYPE.code; /** * HTTP status code for "Requested Range Not Satisfiable" (416). * * @constant {number} */ exports.REQUESTED_RANGE_NOT_SATISFIABLE = constants_1.HTTP_STATUS_MAPPINGS.REQUESTED_RANGE_NOT_SATISFIABLE.code; /** * HTTP status code for "Expectation Failed" (417). * * @constant {number} */ exports.EXPECTATION_FAILED = constants_1.HTTP_STATUS_MAPPINGS.EXPECTATION_FAILED.code; /** * HTTP status code for "I'm a teapot" (418). * * @constant {number} */ exports.IM_A_TEAPOT = constants_1.HTTP_STATUS_MAPPINGS.IM_A_TEAPOT.code; /** * HTTP status code for "Insufficient Space on Resource" (419). * * @constant {number} */ exports.INSUFFICIENT_SPACE_ON_RESOURCE = constants_1.HTTP_STATUS_MAPPINGS.INSUFFICIENT_SPACE_ON_RESOURCE.code; /** * HTTP status code for "Method Failure" (420). * * @constant {number} */ exports.METHOD_FAILURE = constants_1.HTTP_STATUS_MAPPINGS.METHOD_FAILURE.code; /** * HTTP status code for "Misdirected Request" (421). * * @constant {number} */ exports.MISDIRECTED_REQUEST = constants_1.HTTP_STATUS_MAPPINGS.MISDIRECTED_REQUEST.code; /** * HTTP status code for "Unprocessable Entity" (422). * * @constant {number} */ exports.UNPROCESSABLE_ENTITY = constants_1.HTTP_STATUS_MAPPINGS.UNPROCESSABLE_ENTITY.code; /** * HTTP status code for "Locked" (423). * * @constant {number} */ exports.LOCKED = constants_1.HTTP_STATUS_MAPPINGS.LOCKED.code; /** * HTTP status code for "Failed Dependency" (424). * * @constant {number} */ exports.FAILED_DEPENDENCY = constants_1.HTTP_STATUS_MAPPINGS.FAILED_DEPENDENCY.code; /** * HTTP status code for "Too Early" (425). * * @constant {number} */ exports.TOO_EARLY = constants_1.HTTP_STATUS_MAPPINGS.TOO_EARLY.code; /** * HTTP status code for "Upgrade Required" (426). * * @constant {number} */ exports.UPGRADE_REQUIRED = constants_1.HTTP_STATUS_MAPPINGS.UPGRADE_REQUIRED.code; /** * HTTP status code for "Precondition Required" (428). * * @constant {number} */ exports.PRECONDITION_REQUIRED = constants_1.HTTP_STATUS_MAPPINGS.PRECONDITION_REQUIRED.code; /** * HTTP status code for "Too Many Requests" (429). * * @constant {number} */ exports.TOO_MANY_REQUESTS = constants_1.HTTP_STATUS_MAPPINGS.TOO_MANY_REQUESTS.code; /** * HTTP status code for "Request Header Fields Too Large" (431). * * @constant {number} */ exports.REQUEST_HEADER_FIELDS_TOO_LARGE = constants_1.HTTP_STATUS_MAPPINGS.REQUEST_HEADER_FIELDS_TOO_LARGE.code; /** * HTTP status code for "Unavailable For Legal Reasons" (451). * * @constant {number} */ exports.UNAVAILABLE_FOR_LEGAL_REASONS = constants_1.HTTP_STATUS_MAPPINGS.UNAVAILABLE_FOR_LEGAL_REASONS.code; /** * HTTP status code for "Internal Server Error" (500). * * @constant {number} */ exports.INTERNAL_SERVER_ERROR = constants_1.HTTP_STATUS_MAPPINGS.INTERNAL_SERVER_ERROR.code; /** * HTTP status code for "Not Implemented" (501). * * @constant {number} */ exports.NOT_IMPLEMENTED = constants_1.HTTP_STATUS_MAPPINGS.NOT_IMPLEMENTED.code; /** * HTTP status code for "Bad Gateway" (502). * * @constant {number} */ exports.BAD_GATEWAY = constants_1.HTTP_STATUS_MAPPINGS.BAD_GATEWAY.code; /** * HTTP status code for "Service Unavailable" (503). * * @constant {number} */ exports.SERVICE_UNAVAILABLE = constants_1.HTTP_STATUS_MAPPINGS.SERVICE_UNAVAILABLE.code; /** * HTTP status code for "Gateway Timeout" (504). * * @constant {number} */ exports.GATEWAY_TIMEOUT = constants_1.HTTP_STATUS_MAPPINGS.GATEWAY_TIMEOUT.code; /** * HTTP status code for "HTTP Version Not Supported" (505). * * @constant {number} */ exports.HTTP_VERSION_NOT_SUPPORTED = constants_1.HTTP_STATUS_MAPPINGS.HTTP_VERSION_NOT_SUPPORTED.code; /** * HTTP status code for "Variant Also Negotiates" (506). * * @constant {number} */ exports.VARIANT_ALSO_NEGOTIATES = constants_1.HTTP_STATUS_MAPPINGS.VARIANT_ALSO_NEGOTIATES.code; /** * HTTP status code for "Insufficient Storage" (507). * * @constant {number} */ exports.INSUFFICIENT_STORAGE = constants_1.HTTP_STATUS_MAPPINGS.INSUFFICIENT_STORAGE.code; /** * HTTP status code for "Loop Detected" (508). * * @constant {number} */ exports.LOOP_DETECTED = constants_1.HTTP_STATUS_MAPPINGS.LOOP_DETECTED.code; /** * HTTP status code for "Not Extended" (510). * * @constant {number} */ exports.NOT_EXTENDED = constants_1.HTTP_STATUS_MAPPINGS.NOT_EXTENDED.code; /** * HTTP status code for "Network Authentication Required" (511). * * @constant {number} */ exports.NETWORK_AUTHENTICATION_REQUIRED = constants_1.HTTP_STATUS_MAPPINGS.NETWORK_AUTHENTICATION_REQUIRED.code; var EXPORTS = { CODES: constants_1.CODES, getStatusCode: utils_1.getStatusCode, getStatusName: utils_1.getStatusName, getStatusDescription: utils_1.getStatusDescription, isInformational: utils_1.isInformational, isSuccess: utils_1.isSuccess, isRedirectional: utils_1.isRedirectional, isClientError: utils_1.isClientError, isServerError: utils_1.isServerError, getInformationalCodes: utils_1.getInformationalCodes, getSuccessCodes: utils_1.getSuccessCodes, getRedirectionalCodes: utils_1.getRedirectionalCodes, getClientErrorCodes: utils_1.getClientErrorCodes, getServerErrorCodes: utils_1.getServerErrorCodes, isValidStatusCode: utils_1.isValidStatusCode, CONTINUE: exports.CONTINUE, SWITCHING_PROTOCOLS: exports.SWITCHING_PROTOCOLS, PROCESSING: exports.PROCESSING, EARLY_HINTS: exports.EARLY_HINTS, TOO_LONG: exports.TOO_LONG, OK: exports.OK, CREATED: exports.CREATED, ACCEPTED: exports.ACCEPTED, NON_AUTHORITATIVE_INFORMATION: exports.NON_AUTHORITATIVE_INFORMATION, NO_CONTENT: exports.NO_CONTENT, RESET_CONTENT: exports.RESET_CONTENT, PARTIAL_CONTENT: exports.PARTIAL_CONTENT, MULTI_STATUS: exports.MULTI_STATUS, ALREADY_REPORTED: exports.ALREADY_REPORTED, IM_USED: exports.IM_USED, MULTIPLE_CHOICES: exports.MULTIPLE_CHOICES, MOVED_PERMANENTLY: exports.MOVED_PERMANENTLY, MOVED_TEMPORARILY: exports.MOVED_TEMPORARILY, SEE_OTHER: exports.SEE_OTHER, NOT_MODIFIED: exports.NOT_MODIFIED, USE_PROXY: exports.USE_PROXY, SWITCH_PROXY: exports.SWITCH_PROXY, TEMPORARY_REDIRECT: exports.TEMPORARY_REDIRECT, PERMANENT_REDIRECT: exports.PERMANENT_REDIRECT, BAD_REQUEST: exports.BAD_REQUEST, UNAUTHORIZED: exports.UNAUTHORIZED, PAYMENT_REQUIRED: exports.PAYMENT_REQUIRED, FORBIDDEN: exports.FORBIDDEN, NOT_FOUND: exports.NOT_FOUND, METHOD_NOT_ALLOWED: exports.METHOD_NOT_ALLOWED, NOT_ACCEPTABLE: exports.NOT_ACCEPTABLE, PROXY_AUTHENTICATION_REQUIRED: exports.PROXY_AUTHENTICATION_REQUIRED, REQUEST_TIMEOUT: exports.REQUEST_TIMEOUT, CONFLICT: exports.CONFLICT, GONE: exports.GONE, LENGTH_REQUIRED: exports.LENGTH_REQUIRED, PRECONDITION_FAILED: exports.PRECONDITION_FAILED, REQUEST_TOO_LONG: exports.REQUEST_TOO_LONG, REQUEST_URI_TOO_LONG: exports.REQUEST_URI_TOO_LONG, UNSUPPORTED_MEDIA_TYPE: exports.UNSUPPORTED_MEDIA_TYPE, REQUESTED_RANGE_NOT_SATISFIABLE: exports.REQUESTED_RANGE_NOT_SATISFIABLE, EXPECTATION_FAILED: exports.EXPECTATION_FAILED, IM_A_TEAPOT: exports.IM_A_TEAPOT, INSUFFICIENT_SPACE_ON_RESOURCE: exports.INSUFFICIENT_SPACE_ON_RESOURCE, METHOD_FAILURE: exports.METHOD_FAILURE, MISDIRECTED_REQUEST: exports.MISDIRECTED_REQUEST, UNPROCESSABLE_ENTITY: exports.UNPROCESSABLE_ENTITY, LOCKED: exports.LOCKED, FAILED_DEPENDENCY: exports.FAILED_DEPENDENCY, TOO_EARLY: exports.TOO_EARLY, UPGRADE_REQUIRED: exports.UPGRADE_REQUIRED, PRECONDITION_REQUIRED: exports.PRECONDITION_REQUIRED, TOO_MANY_REQUESTS: exports.TOO_MANY_REQUESTS, REQUEST_HEADER_FIELDS_TOO_LARGE: exports.REQUEST_HEADER_FIELDS_TOO_LARGE, UNAVAILABLE_FOR_LEGAL_REASONS: exports.UNAVAILABLE_FOR_LEGAL_REASONS, INTERNAL_SERVER_ERROR: exports.INTERNAL_SERVER_ERROR, NOT_IMPLEMENTED: exports.NOT_IMPLEMENTED, BAD_GATEWAY: exports.BAD_GATEWAY, SERVICE_UNAVAILABLE: exports.SERVICE_UNAVAILABLE, GATEWAY_TIMEOUT: exports.GATEWAY_TIMEOUT, HTTP_VERSION_NOT_SUPPORTED: exports.HTTP_VERSION_NOT_SUPPORTED, VARIANT_ALSO_NEGOTIATES: exports.VARIANT_ALSO_NEGOTIATES, INSUFFICIENT_STORAGE: exports.INSUFFICIENT_STORAGE, LOOP_DETECTED: exports.LOOP_DETECTED, NOT_EXTENDED: exports.NOT_EXTENDED, NETWORK_AUTHENTICATION_REQUIRED: exports.NETWORK_AUTHENTICATION_REQUIRED, }; module.exports = EXPORTS;