Skip to content

Commit e4ee49b

Browse files
committed
feat(response): add all http status codes
1 parent 31e9d06 commit e4ee49b

File tree

2 files changed

+215
-26
lines changed

2 files changed

+215
-26
lines changed

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
};

packages/response/src/response.ts

Lines changed: 112 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +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-
17-
export type Status = 200 | 400 | 401 | 403 | 404 | 409 | 429 | 500 | 503;
5+
export type Status =
6+
| 100
7+
| 101
8+
| 102
9+
| 200
10+
| 201
11+
| 202
12+
| 203
13+
| 204
14+
| 205
15+
| 206
16+
| 207
17+
| 208
18+
| 226
19+
| 300
20+
| 301
21+
| 302
22+
| 303
23+
| 304
24+
| 307
25+
| 308
26+
| 400
27+
| 401
28+
| 402
29+
| 403
30+
| 404
31+
| 405
32+
| 406
33+
| 407
34+
| 408
35+
| 409
36+
| 410
37+
| 411
38+
| 412
39+
| 413
40+
| 414
41+
| 415
42+
| 416
43+
| 417
44+
| 418
45+
| 421
46+
| 422
47+
| 423
48+
| 424
49+
| 425
50+
| 426
51+
| 428
52+
| 429
53+
| 431
54+
| 451
55+
| 500
56+
| 501
57+
| 502
58+
| 503
59+
| 504
60+
| 505
61+
| 506
62+
| 507
63+
| 508
64+
| 510
65+
| 511;
1866

1967
export type Response = { type: Status; payload: unknown };
2068

@@ -23,13 +71,64 @@ const ResponseFunction =
2371
<T>(payload: T) => ({ type: status, payload });
2472

2573
export const Response = {
74+
continue: ResponseFunction(100),
75+
switchingProtocols: ResponseFunction(101),
76+
processing: ResponseFunction(102),
2677
ok: ResponseFunction(200),
78+
created: ResponseFunction(201),
79+
accepted: ResponseFunction(202),
80+
nonAuthoritativeInformation: ResponseFunction(203),
81+
noContent: ResponseFunction(204),
82+
resetContent: ResponseFunction(205),
83+
partialContent: ResponseFunction(206),
84+
multiStatus: ResponseFunction(207),
85+
alreadyReported: ResponseFunction(208),
86+
imUsed: ResponseFunction(226),
87+
multipleChoices: ResponseFunction(300),
88+
movedPermanently: ResponseFunction(301),
89+
found: ResponseFunction(302),
90+
seeOther: ResponseFunction(303),
91+
notModified: ResponseFunction(304),
92+
temporaryRedirect: ResponseFunction(307),
93+
permanentRedirect: ResponseFunction(308),
2794
invalidRequest: ResponseFunction(400),
2895
unauthenticated: ResponseFunction(401),
96+
paymentRequired: ResponseFunction(402),
2997
permissionDenied: ResponseFunction(403),
3098
notFound: ResponseFunction(404),
99+
methodNotAllowed: ResponseFunction(405),
100+
notAcceptable: ResponseFunction(406),
101+
proxyAuthenticationRequired: ResponseFunction(407),
102+
requestTimeout: ResponseFunction(408),
31103
conflict: ResponseFunction(409),
104+
gone: ResponseFunction(410),
105+
lengthRequired: ResponseFunction(411),
106+
preconditionFailed: ResponseFunction(412),
107+
contentTooLarge: ResponseFunction(413),
108+
uriTooLong: ResponseFunction(414),
109+
unsupportedMediaType: ResponseFunction(415),
110+
rangeNotSatisfiable: ResponseFunction(416),
111+
exceptionFailed: ResponseFunction(417),
112+
imATeapot: ResponseFunction(418),
113+
misdirectedRequest: ResponseFunction(421),
114+
unprocessableContent: ResponseFunction(422),
115+
locked: ResponseFunction(423),
116+
failedDependency: ResponseFunction(424),
117+
tooEarly: ResponseFunction(425),
118+
upgradeRequired: ResponseFunction(426),
119+
preconditionRequired: ResponseFunction(428),
32120
rateLimitExceeded: ResponseFunction(429),
121+
requestHeaderFieldsTooLarge: ResponseFunction(431),
122+
unavailableForLegalReasons: ResponseFunction(451),
33123
internalError: ResponseFunction(500),
124+
notImplemented: ResponseFunction(501),
125+
badGateway: ResponseFunction(502),
34126
serviceUnavailable: ResponseFunction(503),
127+
gatewayTimeout: ResponseFunction(504),
128+
httpVersionNotSupported: ResponseFunction(505),
129+
variantAlsoNegotiates: ResponseFunction(506),
130+
insufficientStorage: ResponseFunction(507),
131+
loopDetected: ResponseFunction(508),
132+
notExtended: ResponseFunction(510),
133+
networkAuthenticationRequired: ResponseFunction(511),
35134
};

0 commit comments

Comments
 (0)