Skip to content

Commit 8466572

Browse files
authored
Merge pull request #418 from domoneill18/ft/add-all-status-codes
feat(io-ts-http): add all http status codes
2 parents 42dcb8e + e4ee49b commit 8466572

File tree

3 files changed

+317
-26
lines changed

3 files changed

+317
-26
lines changed
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,131 @@
11
// TODO: Enforce consistency at the type level
22

33
export const HttpToKeyStatus = {
4+
100: 'continue',
5+
101: 'switchingProtocols',
6+
102: 'processing',
47
200: 'ok',
8+
201: 'created',
9+
202: 'accepted',
10+
203: 'nonAuthoritativeInformation',
11+
204: 'noContent',
12+
205: 'resetContent',
13+
206: 'partialContent',
14+
207: 'multiStatus',
15+
208: 'alreadyReported',
16+
226: 'imUsed',
17+
300: 'multipleChoices',
18+
301: 'movedPermanently',
19+
302: 'found',
20+
303: 'seeOther',
21+
304: 'notModified',
22+
307: 'temporaryRedirect',
23+
308: 'permanentRedirect',
524
400: 'invalidRequest',
625
401: 'unauthenticated',
26+
402: 'paymentRequired',
727
403: 'permissionDenied',
828
404: 'notFound',
29+
405: 'methodNotAllowed',
30+
406: 'notAcceptable',
31+
407: 'proxyAuthenticationRequired',
32+
408: 'requestTimeout',
933
409: 'conflict',
34+
410: 'gone',
35+
411: 'lengthRequired',
36+
412: 'preconditionFailed',
37+
413: 'contentTooLarge',
38+
414: 'uriTooLong',
39+
415: 'unsupportedMediaType',
40+
416: 'rangeNotSatisfiable',
41+
417: 'exceptionFailed',
42+
418: 'imATeapot',
43+
421: 'misdirectedRequest',
44+
422: 'unprocessableContent',
45+
423: 'locked',
46+
424: 'failedDependency',
47+
425: 'tooEarly',
48+
426: 'upgradeRequired',
49+
428: 'preconditionRequired',
1050
429: 'rateLimitExceeded',
51+
431: 'requestHeaderFieldsTooLarge',
52+
451: 'unavailableForLegalReasons',
1153
500: 'internalError',
54+
501: 'notImplemented',
55+
502: 'badGateway',
1256
503: 'serviceUnavailable',
57+
504: 'gatewayTimeout',
58+
505: 'httpVersionNotSupported',
59+
506: 'variantAlsoNegotiates',
60+
507: 'insufficientStorage',
61+
508: 'loopDetected',
62+
510: 'notExtended',
63+
511: 'networkAuthenticationRequired',
1364
} as const;
1465

1566
export type HttpToKeyStatus = typeof HttpToKeyStatus;
1667

1768
export const KeyToHttpStatus = {
69+
continue: 100,
70+
switchingProtocols: 101,
71+
processing: 102,
1872
ok: 200,
73+
created: 201,
74+
accepted: 202,
75+
nonAuthoritativeInformation: 203,
76+
noContent: 204,
77+
resetContent: 205,
78+
partialContent: 206,
79+
multiStatus: 207,
80+
alreadyReported: 208,
81+
imUsed: 226,
82+
multipleChoices: 300,
83+
movedPermanently: 301,
84+
found: 302,
85+
seeOther: 303,
86+
notModified: 304,
87+
temporaryRedirect: 307,
88+
permanentRedirect: 308,
1989
invalidRequest: 400,
2090
unauthenticated: 401,
91+
paymentRequired: 402,
2192
permissionDenied: 403,
2293
notFound: 404,
94+
methodNotAllowed: 405,
95+
notAcceptable: 406,
96+
proxyAuthenticationRequired: 407,
97+
requestTimeout: 408,
2398
conflict: 409,
99+
gone: 410,
100+
lengthRequired: 411,
101+
preconditionFailed: 412,
102+
contentTooLarge: 413,
103+
uriTooLong: 414,
104+
unsupportedMediaType: 415,
105+
rangeNotSatisfiable: 416,
106+
exceptionFailed: 417,
107+
imATeapot: 418,
108+
misdirectedRequest: 421,
109+
unprocessableContent: 422,
110+
locked: 423,
111+
failedDependency: 424,
112+
tooEarly: 425,
113+
upgradeRequired: 426,
114+
preconditionRequired: 428,
24115
rateLimitExceeded: 429,
116+
requestHeaderFieldsTooLarge: 431,
117+
unavailableForLegalReasons: 451,
25118
internalError: 500,
119+
notImplemented: 501,
120+
badGateway: 502,
26121
serviceUnavailable: 503,
122+
gatewayTimeout: 504,
123+
httpVersionNotSupported: 505,
124+
variantAlsoNegotiates: 506,
125+
insufficientStorage: 507,
126+
loopDetected: 508,
127+
notExtended: 510,
128+
networkAuthenticationRequired: 511,
27129
} as const;
28130

29131
export type KeyToHttpStatus = typeof KeyToHttpStatus;

packages/response/src/keyed-response.ts

Lines changed: 103 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,67 @@
22
* @api-ts/response
33
*/
44

5-
// HTTP | GRPC | Response
6-
// ----------------------------|--------------------|---------------------------
7-
// 400 (bad request) | INVALID_ARGUMENT | Response.invalidRequest
8-
// 401 (unauthorized) | UNAUTHENTICATED | Response.unauthenticated
9-
// 403 (forbidden) | PERMISSION_DENIED | Response.permissionDenied
10-
// 404 (not found) | NOT_FOUND | Response.notFound
11-
// 405 (method not allowed) | NOT_FOUND | Response.notFound
12-
// 409 (conflict) | ALREADY_EXISTS | Response.conflict
13-
// 429 (rate-limit) | RESOURCE_EXHAUSTED | Response.rateLimitExceeded
14-
// 500 (internal server error) | INTERNAL | Response.internalError
15-
// 503 (service unavailable) | UNAVAILABLE | Response.serviceUnavailable
16-
175
export type KeyedStatus =
6+
| 'continue'
7+
| 'switchingProtocols'
8+
| 'processing'
189
| 'ok'
10+
| 'created'
11+
| 'accepted'
12+
| 'nonAuthoritativeInformation'
13+
| 'noContent'
14+
| 'resetContent'
15+
| 'partialContent'
16+
| 'multiStatus'
17+
| 'alreadyReported'
18+
| 'imUsed'
19+
| 'multipleChoices'
20+
| 'movedPermanently'
21+
| 'found'
22+
| 'seeOther'
23+
| 'notModified'
24+
| 'temporaryRedirect'
25+
| 'permanentRedirect'
1926
| 'invalidRequest'
2027
| 'unauthenticated'
28+
| 'paymentRequired'
2129
| 'permissionDenied'
2230
| 'notFound'
31+
| 'methodNotAllowed'
32+
| 'notAcceptable'
33+
| 'proxyAuthenticationRequired'
34+
| 'requestTimeout'
2335
| 'conflict'
36+
| 'gone'
37+
| 'lengthRequired'
38+
| 'preconditionFailed'
39+
| 'contentTooLarge'
40+
| 'uriTooLong'
41+
| 'unsupportedMediaType'
42+
| 'rangeNotSatisfiable'
43+
| 'exceptionFailed'
44+
| 'imATeapot'
45+
| 'misdirectedRequest'
46+
| 'unprocessableContent'
47+
| 'locked'
48+
| 'failedDependency'
49+
| 'tooEarly'
50+
| 'upgradeRequired'
51+
| 'preconditionRequired'
2452
| 'rateLimitExceeded'
53+
| 'requestHeaderFieldsTooLarge'
54+
| 'unavailableForLegalReasons'
2555
| 'internalError'
26-
| 'serviceUnavailable';
56+
| 'notImplemented'
57+
| 'badGateway'
58+
| 'serviceUnavailable'
59+
| 'gatewayTimeout'
60+
| 'httpVersionNotSupported'
61+
| 'variantAlsoNegotiates'
62+
| 'insufficientStorage'
63+
| 'loopDetected'
64+
| 'notExtended'
65+
| 'networkAuthenticationRequired';
2766

2867
export type KeyedResponse = { type: KeyedStatus; payload: unknown };
2968

@@ -32,13 +71,64 @@ const responseFunction =
3271
<T>(payload: T) => ({ type: status, payload });
3372

3473
export const KeyedResponse = {
74+
continue: responseFunction('continue'),
75+
switchingProtocols: responseFunction('switchingProtocols'),
76+
processing: responseFunction('processing'),
3577
ok: responseFunction('ok'),
78+
created: responseFunction('created'),
79+
accepted: responseFunction('accepted'),
80+
nonAuthoritativeInformation: responseFunction('nonAuthoritativeInformation'),
81+
noContent: responseFunction('noContent'),
82+
resetContent: responseFunction('resetContent'),
83+
partialContent: responseFunction('partialContent'),
84+
multiStatus: responseFunction('multiStatus'),
85+
alreadyReported: responseFunction('alreadyReported'),
86+
imUsed: responseFunction('imUsed'),
87+
multipleChoices: responseFunction('multipleChoices'),
88+
movedPermanently: responseFunction('movedPermanently'),
89+
found: responseFunction('found'),
90+
seeOther: responseFunction('seeOther'),
91+
notModified: responseFunction('notModified'),
92+
temporaryRedirect: responseFunction('temporaryRedirect'),
93+
permanentRedirect: responseFunction('permanentRedirect'),
3694
invalidRequest: responseFunction('invalidRequest'),
3795
unauthenticated: responseFunction('unauthenticated'),
96+
paymentRequired: responseFunction('paymentRequired'),
3897
permissionDenied: responseFunction('permissionDenied'),
3998
notFound: responseFunction('notFound'),
99+
methodNotAllowed: responseFunction('methodNotAllowed'),
100+
notAcceptable: responseFunction('notAcceptable'),
101+
proxyAuthenticationRequired: responseFunction('proxyAuthenticationRequired'),
102+
requestTimeout: responseFunction('requestTimeout'),
40103
conflict: responseFunction('conflict'),
104+
gone: responseFunction('gone'),
105+
lengthRequired: responseFunction('lengthRequired'),
106+
preconditionFailed: responseFunction('preconditionFailed'),
107+
contentTooLarge: responseFunction('contentTooLarge'),
108+
uriTooLong: responseFunction('uriTooLong'),
109+
unsupportedMediaType: responseFunction('unsupportedMediaType'),
110+
rangeNotSatisfiable: responseFunction('rangeNotSatisfiable'),
111+
exceptionFailed: responseFunction('exceptionFailed'),
112+
imATeapot: responseFunction('imATeapot'),
113+
misdirectedRequest: responseFunction('misdirectedRequest'),
114+
unprocessableContent: responseFunction('unprocessableContent'),
115+
locked: responseFunction('locked'),
116+
failedDependency: responseFunction('failedDependency'),
117+
tooEarly: responseFunction('tooEarly'),
118+
upgradeRequired: responseFunction('upgradeRequired'),
119+
preconditionRequired: responseFunction('preconditionRequired'),
41120
rateLimitExceeded: responseFunction('rateLimitExceeded'),
121+
requestHeaderFieldsTooLarge: responseFunction('requestHeaderFieldsTooLarge'),
122+
unavailableForLegalReasons: responseFunction('unavailableForLegalReasons'),
42123
internalError: responseFunction('internalError'),
124+
notImplemented: responseFunction('notImplemented'),
125+
badGateway: responseFunction('badGateway'),
43126
serviceUnavailable: responseFunction('serviceUnavailable'),
127+
gatewayTimeout: responseFunction('gatewayTimeout'),
128+
httpVersionNotSupported: responseFunction('httpVersionNotSupported'),
129+
variantAlsoNegotiates: responseFunction('variantAlsoNegotiates'),
130+
insufficientStorage: responseFunction('insufficientStorage'),
131+
loopDetected: responseFunction('loopDetected'),
132+
notExtended: responseFunction('notExtended'),
133+
networkAuthenticationRequired: responseFunction('networkAuthenticationRequired'),
44134
};

0 commit comments

Comments
 (0)