File tree Expand file tree Collapse file tree 1 file changed +59
-0
lines changed Expand file tree Collapse file tree 1 file changed +59
-0
lines changed Original file line number Diff line number Diff line change 1+ export enum HTTPStatus {
2+ OK = 200 ,
3+ CREATED = 201 ,
4+ NO_CONTENT = 204 ,
5+ NOT_MODIFIED = 304 ,
6+ BAD_REQUEST = 400 ,
7+ UNAUTHORIZED = 401 ,
8+ FORBIDDEN = 403 ,
9+ NOT_FOUND = 404 ,
10+ CONFLICT = 409 ,
11+ VAILDATION_FAILED = 422 ,
12+ INTERNAL_SERVER_ERROR = 500 ,
13+ BAD_GATEWAY = 502 ,
14+ SERVICE_UNAVAILABLE = 503 ,
15+ GATEWAY_TIMEOUT = 504 ,
16+ UNKNOWN = - 1 ,
17+ }
18+
19+ export interface HTTPStatusRes {
20+ code : HTTPStatus ;
21+ data : string ;
22+ }
23+
24+ const t = ( v : HTTPStatus ) : HTTPStatusRes => ( { code : v , data : HTTPStatus [ v ] } ) ;
25+
26+ export default ( status : number ) : HTTPStatusRes => {
27+ switch ( status ) {
28+ case 200 :
29+ return t ( HTTPStatus . OK ) ;
30+ case 201 :
31+ return t ( HTTPStatus . CREATED ) ;
32+ case 204 :
33+ return t ( HTTPStatus . NO_CONTENT ) ;
34+ case 304 :
35+ return t ( HTTPStatus . NOT_MODIFIED ) ;
36+ case 400 :
37+ return t ( HTTPStatus . BAD_REQUEST ) ;
38+ case 401 :
39+ return t ( HTTPStatus . UNAUTHORIZED ) ;
40+ case 403 :
41+ return t ( HTTPStatus . FORBIDDEN ) ;
42+ case 404 :
43+ return t ( HTTPStatus . NOT_FOUND ) ;
44+ case 409 :
45+ return t ( HTTPStatus . CONFLICT ) ;
46+ case 422 :
47+ return t ( HTTPStatus . VAILDATION_FAILED ) ;
48+ case 500 :
49+ return t ( HTTPStatus . INTERNAL_SERVER_ERROR ) ;
50+ case 502 :
51+ return t ( HTTPStatus . BAD_GATEWAY ) ;
52+ case 503 :
53+ return t ( HTTPStatus . SERVICE_UNAVAILABLE ) ;
54+ case 504 :
55+ return t ( HTTPStatus . GATEWAY_TIMEOUT ) ;
56+ default :
57+ return t ( HTTPStatus . UNKNOWN ) ;
58+ }
59+ } ;
You can’t perform that action at this time.
0 commit comments