UNPKG

@js-thing/http-status-codes

Version:

Contains properly documented HTTP status code enums, reason phrases and helpers as defined in RFC

56 lines 2.44 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.isServerErrorStatus = exports.isServerErrorReasonPhrase = exports.is5xxServerErrorStatusCode = exports.isServerErrorStatusCode = void 0; var HttpStatusCodes_1 = require("../HttpStatusCodes"); var HttpReasonPhrases_1 = require("../HttpReasonPhrases"); /** * Checks whether the status code belongs to `HttpServerErrorStatusCodes` enum. * The range is all standard code between [500 - 599] * * To check the entire 5xx range use `is5xxServerErrorStatusCode(code: number)` instead. * @param statusCode - The integer status code. e.g. 100 * @returns `true` if matches `false` otherwise */ var isServerErrorStatusCode = function (statusCode) { return HttpStatusCodes_1.HttpServerErrorStatusCodes[statusCode] !== undefined; }; exports.isServerErrorStatusCode = isServerErrorStatusCode; /** * Checks whether the status code belongs to 5xx family of status codes. * * @param statusCode - The integer status code. e.g. 100 * @returns `true` if matches `false` otherwise */ var is5xxServerErrorStatusCode = function (statusCode) { return statusCode >= 500 && statusCode <= 599; }; exports.is5xxServerErrorStatusCode = is5xxServerErrorStatusCode; /** * Checks whether the input string belongs to `HttpServerErrorReasonPhrases` enum. * * The match is case sensitive * * @param reasonPhrase - The reason phrase. e.g. 'Ok' * @returns `true` if matches `false` otherwise */ var isServerErrorReasonPhrase = function (reasonPhrase) { return Object.values(HttpReasonPhrases_1.HttpServerErrorReasonPhrases).includes(reasonPhrase) === true; }; exports.isServerErrorReasonPhrase = isServerErrorReasonPhrase; /** * Checks whether the input integer or string belongs to * `HttpServerErrorStatusCodes` or `HttpServerErrorReasonPhrases` enum. * For integer input, the range is all standard code between [500 - 599]. * For string input, the match is case sensitive. * * To check the entire 5xx range use `is5xxServerErrorStatusCode(code: number)` instead. * @param status - e.g. 'Ok' or 200 * @returns `true` if matches `false` otherwise */ var isServerErrorStatus = function (status) { return exports.isServerErrorStatusCode(status) || exports.isServerErrorReasonPhrase(status); }; exports.isServerErrorStatus = isServerErrorStatus; exports.default = exports.isServerErrorStatus; //# sourceMappingURL=isServerErrorStatus.js.map