5 changed files with 123 additions and 0 deletions
@ -0,0 +1,44 @@ |
|||||
|
export enum HttpStatusCode { |
||||
|
Accepted = 202, |
||||
|
Ambiguous = 300, |
||||
|
BadGateway = 502, |
||||
|
BadRequest = 400, |
||||
|
Conflict = 409, |
||||
|
Continue = 100, |
||||
|
Created = 201, |
||||
|
ExpectationFailed = 417, |
||||
|
Forbidden = 403, |
||||
|
GatewayTimeout = 504, |
||||
|
Gone = 410, |
||||
|
HttpVersionNotSupported = 505, |
||||
|
InternalServerError = 500, |
||||
|
LengthRequired = 411, |
||||
|
MethodNotAllowed = 405, |
||||
|
Moved = 301, |
||||
|
NoContent = 204, |
||||
|
NonAuthoritativeInformation = 203, |
||||
|
NotAcceptable = 406, |
||||
|
NotFound = 404, |
||||
|
NotImplemented = 501, |
||||
|
NotModified = 304, |
||||
|
OK = 200, |
||||
|
PartialContent = 206, |
||||
|
PaymentRequired = 402, |
||||
|
PreconditionFailed = 412, |
||||
|
ProxyAuthenticationRequired = 407, |
||||
|
Redirect = 302, |
||||
|
RedirectKeepVerb = 307, |
||||
|
RedirectMethod = 303, |
||||
|
RequestedRangeNotSatisfiable = 416, |
||||
|
RequestEntityTooLarge = 413, |
||||
|
RequestTimeout = 408, |
||||
|
RequestUriTooLong = 414, |
||||
|
ResetContent = 205, |
||||
|
ServiceUnavailable = 503, |
||||
|
SwitchingProtocols = 101, |
||||
|
Unauthorized = 401, |
||||
|
UnsupportedMediaType = 415, |
||||
|
Unused = 306, |
||||
|
UpgradeRequired = 426, |
||||
|
UseProxy = 305, |
||||
|
} |
||||
@ -0,0 +1 @@ |
|||||
|
export * from './httpStatus'; |
||||
@ -1,3 +1,4 @@ |
|||||
export * from './useErrorFormat'; |
export * from './useErrorFormat'; |
||||
|
export * from './useHttpStatusCodeMap'; |
||||
export * from './useRequest'; |
export * from './useRequest'; |
||||
export * from './useWrapperResult'; |
export * from './useWrapperResult'; |
||||
|
|||||
@ -0,0 +1,76 @@ |
|||||
|
import { HttpStatusCode } from '../constants/httpStatus'; |
||||
|
|
||||
|
export function useHttpStatusCodeMap() { |
||||
|
const httpStatusCodeMap: { [key: number]: string } = { |
||||
|
[HttpStatusCode.Accepted]: '202 - Accepted', |
||||
|
[HttpStatusCode.Ambiguous]: '300 - Ambiguous/Multiple Choices', |
||||
|
[HttpStatusCode.BadGateway]: '502 - Bad Gateway', |
||||
|
[HttpStatusCode.BadRequest]: '400 - Bad Request', |
||||
|
[HttpStatusCode.Conflict]: '409 - Conflict', |
||||
|
[HttpStatusCode.Continue]: '100 - Continue', |
||||
|
[HttpStatusCode.Created]: '201 - Created', |
||||
|
[HttpStatusCode.ExpectationFailed]: '417 - Expectation Failed', |
||||
|
[HttpStatusCode.Forbidden]: '403 - Forbidden', |
||||
|
[HttpStatusCode.GatewayTimeout]: '504 - Gateway Timeout', |
||||
|
[HttpStatusCode.Gone]: '410 - Gone', |
||||
|
[HttpStatusCode.HttpVersionNotSupported]: |
||||
|
'505 - Http Version Not Supported', |
||||
|
[HttpStatusCode.InternalServerError]: '500 - Internal Server Error', |
||||
|
[HttpStatusCode.LengthRequired]: '411 - Length Required', |
||||
|
[HttpStatusCode.MethodNotAllowed]: '405 - Method Not Allowed', |
||||
|
[HttpStatusCode.Moved]: '301 - Moved/Moved Permanently', |
||||
|
[HttpStatusCode.NoContent]: '204 - No Content', |
||||
|
[HttpStatusCode.NonAuthoritativeInformation]: |
||||
|
'203 - Non Authoritative Information', |
||||
|
[HttpStatusCode.NotAcceptable]: '406 - Not Acceptable', |
||||
|
[HttpStatusCode.NotFound]: '404 - Not Found', |
||||
|
[HttpStatusCode.NotImplemented]: '501 - Not Implemented', |
||||
|
[HttpStatusCode.NotModified]: '304 - Not Modified', |
||||
|
[HttpStatusCode.OK]: '200 - OK', |
||||
|
[HttpStatusCode.PartialContent]: '206 - Partial Content', |
||||
|
[HttpStatusCode.PaymentRequired]: '402 - Payment Required', |
||||
|
[HttpStatusCode.PreconditionFailed]: '412 - Precondition Failed', |
||||
|
[HttpStatusCode.ProxyAuthenticationRequired]: |
||||
|
'407 - Proxy Authentication Required', |
||||
|
[HttpStatusCode.Redirect]: '302 - Found/Redirect', |
||||
|
[HttpStatusCode.RedirectKeepVerb]: |
||||
|
'307 - Redirect Keep Verb/Temporary Redirect', |
||||
|
[HttpStatusCode.RedirectMethod]: '303 - Redirect Method/See Other', |
||||
|
[HttpStatusCode.RequestedRangeNotSatisfiable]: |
||||
|
'416 - Requested Range Not Satisfiable', |
||||
|
[HttpStatusCode.RequestEntityTooLarge]: '413 - Request Entity Too Large', |
||||
|
[HttpStatusCode.RequestTimeout]: '408 - Request Timeout', |
||||
|
[HttpStatusCode.RequestUriTooLong]: '414 - Request Uri Too Long', |
||||
|
[HttpStatusCode.ResetContent]: '205 - Reset Content', |
||||
|
[HttpStatusCode.ServiceUnavailable]: '503 - Service Unavailable', |
||||
|
[HttpStatusCode.SwitchingProtocols]: '101 - Switching Protocols', |
||||
|
[HttpStatusCode.Unauthorized]: '401 - Unauthorized', |
||||
|
[HttpStatusCode.UnsupportedMediaType]: '415 - Unsupported Media Type', |
||||
|
[HttpStatusCode.Unused]: '306 - Unused', |
||||
|
[HttpStatusCode.UpgradeRequired]: '426 - Upgrade Required', |
||||
|
[HttpStatusCode.UseProxy]: '305 - Use Proxy', |
||||
|
}; |
||||
|
|
||||
|
function getHttpStatusColor(statusCode: HttpStatusCode) { |
||||
|
if (statusCode < 200) { |
||||
|
return 'default'; |
||||
|
} |
||||
|
if (statusCode >= 200 && statusCode < 300) { |
||||
|
return 'success'; |
||||
|
} |
||||
|
if (statusCode >= 300 && statusCode < 400) { |
||||
|
return 'processing'; |
||||
|
} |
||||
|
if (statusCode >= 400 && statusCode < 500) { |
||||
|
return 'warning'; |
||||
|
} |
||||
|
if (statusCode >= 500) { |
||||
|
return 'error'; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
return { |
||||
|
getHttpStatusColor, |
||||
|
httpStatusCodeMap, |
||||
|
}; |
||||
|
} |
||||
Loading…
Reference in new issue