diff --git a/index.js b/index.js index 0abba3f478..4920f55c41 100644 --- a/index.js +++ b/index.js @@ -16,6 +16,7 @@ const { spread, toFormData, AxiosHeaders, + HttpStatusCode, formToJSON, mergeConfig } = axios; @@ -34,6 +35,7 @@ export { spread, toFormData, AxiosHeaders, + HttpStatusCode, formToJSON, mergeConfig } diff --git a/lib/axios.js b/lib/axios.js index b725724356..c97e062e00 100644 --- a/lib/axios.js +++ b/lib/axios.js @@ -15,6 +15,7 @@ import AxiosError from './core/AxiosError.js'; import spread from './helpers/spread.js'; import isAxiosError from './helpers/isAxiosError.js'; import AxiosHeaders from "./core/AxiosHeaders.js"; +import HttpStatusCode from './helpers/HttpStatusCode.js'; /** * Create an instance of Axios @@ -77,6 +78,8 @@ axios.AxiosHeaders = AxiosHeaders; axios.formToJSON = thing => formDataToJSON(utils.isHTMLForm(thing) ? new FormData(thing) : thing); +axios.HttpStatusCode = HttpStatusCode; + axios.default = axios; // this module should only have a default export diff --git a/lib/helpers/HttpStatusCode.js b/lib/helpers/HttpStatusCode.js new file mode 100644 index 0000000000..b3e7adcab0 --- /dev/null +++ b/lib/helpers/HttpStatusCode.js @@ -0,0 +1,71 @@ +const HttpStatusCode = { + Continue: 100, + SwitchingProtocols: 101, + Processing: 102, + EarlyHints: 103, + Ok: 200, + Created: 201, + Accepted: 202, + NonAuthoritativeInformation: 203, + NoContent: 204, + ResetContent: 205, + PartialContent: 206, + MultiStatus: 207, + AlreadyReported: 208, + ImUsed: 226, + MultipleChoices: 300, + MovedPermanently: 301, + Found: 302, + SeeOther: 303, + NotModified: 304, + UseProxy: 305, + Unused: 306, + TemporaryRedirect: 307, + PermanentRedirect: 308, + BadRequest: 400, + Unauthorized: 401, + PaymentRequired: 402, + Forbidden: 403, + NotFound: 404, + MethodNotAllowed: 405, + NotAcceptable: 406, + ProxyAuthenticationRequired: 407, + RequestTimeout: 408, + Conflict: 409, + Gone: 410, + LengthRequired: 411, + PreconditionFailed: 412, + PayloadTooLarge: 413, + UriTooLong: 414, + UnsupportedMediaType: 415, + RangeNotSatisfiable: 416, + ExpectationFailed: 417, + ImATeapot: 418, + MisdirectedRequest: 421, + UnprocessableEntity: 422, + Locked: 423, + FailedDependency: 424, + TooEarly: 425, + UpgradeRequired: 426, + PreconditionRequired: 428, + TooManyRequests: 429, + RequestHeaderFieldsTooLarge: 431, + UnavailableForLegalReasons: 451, + InternalServerError: 500, + NotImplemented: 501, + BadGateway: 502, + ServiceUnavailable: 503, + GatewayTimeout: 504, + HttpVersionNotSupported: 505, + VariantAlsoNegotiates: 506, + InsufficientStorage: 507, + LoopDetected: 508, + NotExtended: 510, + NetworkAuthenticationRequired: 511, +}; + +Object.entries(HttpStatusCode).forEach(([key, value]) => { + HttpStatusCode[value] = key; +}); + +export default HttpStatusCode; diff --git a/test/specs/instance.spec.js b/test/specs/instance.spec.js index e95a3cf043..78fd7b3eb6 100644 --- a/test/specs/instance.spec.js +++ b/test/specs/instance.spec.js @@ -28,7 +28,8 @@ describe('instance', function () { 'default', 'toFormData', 'formToJSON', - 'AxiosHeaders' + 'AxiosHeaders', + 'HttpStatusCode' ].indexOf(prop) > -1) { continue; }