@applicaster/zapp-react-native-utils
Version:
Applicaster Zapp React Native utilities package
104 lines (93 loc) • 2.61 kB
text/typescript
// Was copied from https://github.com/axios/axios/blob/v1.x/index.d.ts#L128 must be removed after axios update
export enum 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,
}
export class HttpStatusCodeHelper {
static fromStatusCode(statusCode: number): HttpStatusCode | number {
if (!statusCode) return -1;
const enumMemberName = HttpStatusCode[statusCode];
if (enumMemberName !== undefined) {
return HttpStatusCode[enumMemberName as keyof typeof HttpStatusCode];
}
// @ts-ignore
return statusCode;
}
static informational(statusCode: HttpStatusCode): boolean {
return statusCode >= 100 && statusCode < 200;
}
static successful(statusCode: HttpStatusCode): boolean {
return statusCode >= 200 && statusCode < 300;
}
static redirection(statusCode: HttpStatusCode): boolean {
return statusCode >= 300 && statusCode < 400;
}
static clientError(statusCode: HttpStatusCode): boolean {
return statusCode >= 400 && statusCode < 500;
}
static serverError(statusCode: HttpStatusCode): boolean {
return statusCode >= 500 && statusCode < 600;
}
}
;