-
Notifications
You must be signed in to change notification settings - Fork 0
/
httpStatus.ts
315 lines (281 loc) · 9.67 KB
/
httpStatus.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
/**
* Standard HTTP status codes.
* @see <a href="https://tools.ietf.org/html/rfc4918">https://tools.ietf.org/html/rfc4918</a>
* @see <a href="https://tools.ietf.org/html/rfc7231">https://tools.ietf.org/html/rfc7231</a>
*/
export const httpStatusCode = {
/**
* Status codes for successful responses.
*/
success: {
/**
* The request has succeeded. The payload depends on the request method.
*
* GET a representation of the target resource,
*
* HEAD the same representation as GET, but without the representation
* data,
*
* POST a representation of the status of, or results obtained from,
* the action,
*
* PUT, DELETE a representation of the status of the action,
*
* OPTIONS a representation of the communications options,
*
* TRACE a representation of the request message as received by the end
* server.
*/
OK: 200,
/**
* The request has been fulfilled and has resulted in one or more new
* resources being created.
*/
CREATED: 201,
/**
* The request has been accepted for processing, but the processing has
* not been completed. The primary resource created by the request is
* identified by either a Location header field in the response or, if
* no Location field is received, by the effective request URI.
*/
ACCEPTED: 202,
/**
* The request was successful but the enclosed payload has been modified
* from that of the origin server's 200 (OK) response by a transforming
* proxy.
*/
NON_AUTHORITATIVE_INFORMATION: 203,
/**
* The server has successfully fulfilled the request and there is no
* content to send in the response payload body.
*/
NO_CONTENT: 204,
/**
* The server has fulfilled the request and desires that the user agent
* reset the "document view", which caused the request to be sent, to
* its original state as received from the origin server.
*/
RESET_CONTENT: 205
},
/**
* Status codes for redirect. Pay special attention to which one is used
* because they have subtle differences in browser and search engine behavior.
*/
redirect: {
/**
* The target resource has more than one representation, each with its own
* more specific identifier, and information about the alternatives is being
* provided so that the user (or user agent) can select a preferred
* representation by redirecting its request to one or more of those
* identifiers.
*/
MULTIPLE_CHOICES: 300,
/**
* The resource moved permanently. Browsers will change POST to GET
* on redirect. Search engines will update their index.
*
* Include a Location header field in the response.
*/
MOVED_PERMANENTLY: 301,
/**
* The resource moved temporarily. Browsers will change POST to GET
* on redirect. Search engines will *not* update their index.
*
* Include a Location header field in the response.
*/
FOUND: 302,
/**
* The server is redirecting the user agent to a different resource, as
* indicated by a URI in the Location header field, which is intended to
* provide an indirect response to the original request.
*/
SEE_OTHER: 303,
/**
* Cache hit. No content is sent. This is determined by the request
* headers If-Modified-Since or If-None-Match.
*/
NOT_MODIFIED: 304,
/**
* The resource moved temporarily and browsers should resubmit,
* preserving the method and body. Don't use for GET.
* Search engines will update their index.
*
* Include a Location header field in the response.
*/
TEMPORARY_REDIRECT: 307,
/**
* The resource moved permanently and browsers should resubmit,
* preserving the method and body. Don't use for GET.
* Search engines will *not* update their index.
*
* Include a Location header field in the response.
*/
PERMANENT_REDIRECT: 308
},
/**
* The client screwed up.
*/
clientError: {
/**
* The request could not be understood by the server due to malformed
* syntax. The client SHOULD NOT repeat the request without modifications.
* For example the JSON body could not be parsed.
*/
BAD_REQUEST: 400,
/**
* Authentication is required and the user is not logged in.
*/
UNAUTHORIZED: 401,
/**
* The user is authenticated but does not have permission.
*/
FORBIDDEN: 403,
/**
* The requested resource was not found.
*/
NOT_FOUND: 404,
/**
* The resource does not support the given method.
* The origin server MUST generate an Allow header field
* containing a list of the supported methods.
*/
METHOD_NOT_ALLOWED: 405,
/**
* The target resource does not have a current representation that would
* be acceptable to the user agent, according to the proactive negotiation
* header fields received in the request.
*/
NOT_ACCEPTABLE: 406,
/**
* The request was understood, and semantically correct, but conflicts
* with the current state. For example: the type is locked.
*/
CONFLICT: 409,
/**
* Access to the target resource is no longer available at the origin server
* and this condition is likely to be permanent.
*
* The 410 response is primarily intended to assist the task of web
* maintenance by notifying the recipient that the resource is
* intentionally unavailable and that the server owners desire that
* remote links to that resource be removed.
*/
GONE: 410,
/**
* The server refuses to accept the request without a defined Content-Length.
*/
LENGTH_REQUIRED: 411,
/**
* The request is larger than the server is willing or able to process.
*/
PAYLOAD_TOO_LARGE: 413,
/**
* The request type has a media type which the server or resource
* does not support.
*/
UNSUPPORTED_MEDIA_TYPE: 415,
/**
* The client has asked for a portion of the file (byte serving), but
* the server cannot supply that portion.
*/
REQUESTED_RANGE_NOT_SATISFIABLE: 416,
/**
* The expectation given in the request's Expect header field could not
* be met.
*/
EXPECTATION_FAILED: 417,
/**
* The request is syntactically correct, but contains semantic errors.
* For example a string was expected but got a number.
* @see <a href="https://tools.ietf.org/html/rfc4918#section-11.2">https://tools.ietf.org/html/rfc4918#section-11.2</a>
*/
UNPROCESSABLE_ENTITY: 422,
/**
* The user has sent too many requests in a given amount of time.
*/
TOO_MANY_REQUESTS: 429
},
/**
* The server screwed up.
*/
serverError: {
/**
* Generic server-side error.
*/
INTERNAL_SERVER_ERROR: 500,
/**
* Usually implies future availability.
*/
NOT_IMPLEMENTED: 501,
/**
* Received an invalid response from an inbound server it accessed while
* acting as a proxy.
*/
BAD_GATEWAY: 502,
/**
* A service is temporarily down.
*/
SERVICE_UNAVAILABLE: 503,
/**
* Did not receive a timely response from an upstream server while acting
* as a proxy.
*/
GATEWAY_TIMEOUT: 504,
}
};
export const httpStatusString: { [statusCode: number]: string } = {
200: "OK",
201: "Created",
202: "Accepted",
203: "Non Authoritative Info",
204: "No Content",
205: "Reset Content",
206: "Partial Content",
207: "Multi Status",
208: "Already Reported",
226: "IM Used",
300: "Multiple Choices",
301: "Moved Permanently",
302: "Found",
303: "See Other",
304: "Not Modified",
305: "Use Proxy",
307: "Temporary Redirect",
308: "Permanent Redirect",
400: "Bad Request",
401: "Unauthorized",
402: "Payment Required",
403: "Forbidden",
404: "Not Found",
405: "Method Not Allowed",
407: "Proxy Auth Required",
408: "Request Timeout",
409: "Conflict",
410: "Gone",
411: "Length Required",
412: "Precondition Failed",
413: "Payload Too Large",
414: "Request URI Too Long",
415: "Unsupported Media Type",
416: "Range Not Satisfiable",
417: "Expectation Failed",
422: "Unprocessable Entity",
423: "Locked",
424: "Failed Dependency",
426: "Upgrade Required",
428: "Precondition Required",
429: "Too Many Requests",
431: "Request Header Fields Too Large",
451: "Unavailable For Legal Reasons",
500: "Internal Server Error",
501: "Not Implemented",
502: "Bad Gateway",
503: "Service Unavailable",
504: "Gateway Timeout",
505: "HTTP Version Not Supported",
506: "Variant Also Negotiates",
507: "Insufficient Storage",
508: "Loop Detected",
510: "Not Extended",
511: "Network Authentication Required"
};