-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhttp_status.ts
59 lines (56 loc) · 1.53 KB
/
http_status.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
export enum HTTPStatus {
OK = 200,
CREATED = 201,
NO_CONTENT = 204,
NOT_MODIFIED = 304,
BAD_REQUEST = 400,
UNAUTHORIZED = 401,
FORBIDDEN = 403,
NOT_FOUND = 404,
CONFLICT = 409,
VAILDATION_FAILED = 422,
INTERNAL_SERVER_ERROR = 500,
BAD_GATEWAY = 502,
SERVICE_UNAVAILABLE = 503,
GATEWAY_TIMEOUT = 504,
UNKNOWN = -1,
}
export interface HTTPStatusRes {
code: HTTPStatus
data: string
}
const t = (v: HTTPStatus): HTTPStatusRes => ({ code: v, data: HTTPStatus[v] })
export default (status: number): HTTPStatusRes => {
switch (status) {
case 200:
return t(HTTPStatus.OK)
case 201:
return t(HTTPStatus.CREATED)
case 204:
return t(HTTPStatus.NO_CONTENT)
case 304:
return t(HTTPStatus.NOT_MODIFIED)
case 400:
return t(HTTPStatus.BAD_REQUEST)
case 401:
return t(HTTPStatus.UNAUTHORIZED)
case 403:
return t(HTTPStatus.FORBIDDEN)
case 404:
return t(HTTPStatus.NOT_FOUND)
case 409:
return t(HTTPStatus.CONFLICT)
case 422:
return t(HTTPStatus.VAILDATION_FAILED)
case 500:
return t(HTTPStatus.INTERNAL_SERVER_ERROR)
case 502:
return t(HTTPStatus.BAD_GATEWAY)
case 503:
return t(HTTPStatus.SERVICE_UNAVAILABLE)
case 504:
return t(HTTPStatus.GATEWAY_TIMEOUT)
default:
return t(HTTPStatus.UNKNOWN)
}
}