Skip to content

Commit 1a90a60

Browse files
committed
Add description and missing statuses to client error responses
1 parent 7742b5c commit 1a90a60

File tree

5 files changed

+85
-55
lines changed

5 files changed

+85
-55
lines changed

src/StatusCode/index.ts

Lines changed: 38 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -102,107 +102,119 @@ export enum StatusCode {
102102
*/
103103
PERMANENT_REDIRECT = 308,
104104
/**
105-
* @description - @
105+
* @description The server cannot or will not process the request due to something that is perceived to be a client error (e.g., malformed request syntax, invalid request message framing, or deceptive request routing).
106106
*/
107107
BAD_REQUEST = 400,
108108
/**
109-
* @description - @
109+
* @description Although the HTTP standard specifies "unauthorized", semantically this response means "unauthenticated". That is, the client must authenticate itself to get the requested response.
110110
*/
111111
UNAUTHORIZED = 401,
112112
/**
113-
* @description - @
113+
* @description This response code is reserved for future use. The initial aim for creating this code was using it for digital payment systems, however this status code is used very rarely and no standard convention exists.
114114
*/
115115
PAYMENT_REQUIRED = 402,
116116
/**
117-
* @description - @
117+
* @description The client does not have access rights to the content; that is, it is unauthorized, so the server is refusing to give the requested resource. Unlike 401 Unauthorized, the client's identity is known to the server.
118118
*/
119119
FORBIDDEN = 403,
120120
/**
121-
* @description - @
121+
* @description The server can not find the requested resource. In the browser, this means the URL is not recognized. In an API, this can also mean that the endpoint is valid but the resource itself does not exist. Servers may also send this response instead of 403 Forbidden to hide the existence of a resource from an unauthorized client. This response code is probably the most well known due to its frequent occurrence on the web.
122122
*/
123123
NOT_FOUND = 404,
124124
/**
125-
* @description - @
125+
* @description The request method is known by the server but is not supported by the target resource. For example, an API may not allow calling DELETE to remove a resource.
126126
*/
127127
METHOD_NOT_ALLOWED = 405,
128128
/**
129-
* @description - @
129+
* @description This response is sent when the web server, after performing server-driven content negotiation, doesn't find any content that conforms to the criteria given by the user agent.
130130
*/
131131
NOT_ACCEPTABLE = 406,
132132
/**
133-
* @description - @
133+
* @description This is similar to 401 Unauthorized but authentication is needed to be done by a proxy.
134134
*/
135135
PROXY_AUTHENTICATION_REQUIRED = 407,
136136
/**
137-
* @description - @
137+
* @description This response is sent on an idle connection by some servers, even without any previous request by the client. It means that the server would like to shut down this unused connection.
138138
*/
139139
REQUEST_TIMEOUT = 408,
140140
/**
141-
* @description - @
141+
* @description This response is sent when a request conflicts with the current state of the server.
142142
*/
143143
CONFLICT = 409,
144144
/**
145-
* @description - @
145+
* @description This response is sent when the requested content has been permanently deleted from server, with no forwarding address. Clients are expected to remove their caches and links to the resource. The HTTP specification intends this status code to be used for "limited-time, promotional services". APIs should not feel compelled to indicate resources that have been deleted with this status code.
146146
*/
147147
GONE = 410,
148148
/**
149-
* @description - @
149+
* @description Server rejected the request because the Content-Length header field is not defined and the server requires it.
150150
*/
151151
LENGTH_REQUIRED = 411,
152152
/**
153-
* @description - @
153+
* @description The client has indicated preconditions in its headers which the server does not meet.
154154
*/
155155
PRECONDITION_FAILED = 412,
156156
/**
157-
* @description - @
157+
* @description Request entity is larger than limits defined by server. The server might close the connection or return an Retry-After header field.
158158
*/
159159
PAYLOAD_TOO_LARGE = 413,
160160
/**
161-
* @description - @
161+
* @description The URI requested by the client is longer than the server is willing to interpret.
162162
*/
163163
URI_TOO_LONG = 414,
164164
/**
165-
* @description - @
165+
* @description The media format of the requested data is not supported by the server, so the server is rejecting the request.
166166
*/
167167
UNSUPPORTED_MEDIA_TYPE = 415,
168168
/**
169-
* @description - @
169+
* @description The range specified by the Range header field in the request cannot be fulfilled. It's possible that the range is outside the size of the target URI's data.
170170
*/
171171
RANGE_NOT_SATISFIABLE = 416,
172172
/**
173-
* @description - @
173+
* @description This response code means the expectation indicated by the Expect request header field cannot be met by the server.
174174
*/
175175
EXPECTATION_FAILED = 417,
176176
/**
177-
* @description - @
177+
* @description The server refuses the attempt to brew coffee with a teapot.
178178
*/
179179
IM_A_TEAPOT = 418,
180180
/**
181-
* @description - @
181+
* @description The request was directed at a server that is not able to produce a response. This can be sent by a server that is not configured to produce responses for the combination of scheme and authority that are included in the request URI.
182+
*/
183+
MISDIRECTED_REQUEST = 421,
184+
/**
185+
* @description The request was well-formed but was unable to be followed due to semantic errors.
182186
*/
183187
UNPROCESSABLE_ENTITY = 422,
184188
/**
185-
* @description - @
189+
* @description The resource that is being accessed is locked.
190+
*/
191+
LOCKED = 423,
192+
/**
193+
* @description The request failed due to failure of a previous request.
194+
*/
195+
FAILED_DEPENDENCY = 424,
196+
/**
197+
* @description Indicates that the server is unwilling to risk processing a request that might be replayed.
186198
*/
187199
TOO_EARLY = 425,
188200
/**
189-
* @description - @
201+
* @description The server refuses to perform the request using the current protocol but might be willing to do so after the client upgrades to a different protocol. The server sends an Upgrade header in a 426 response to indicate the required protocol(s).
190202
*/
191203
UPGRADE_REQUIRED = 426,
192204
/**
193-
* @description - @
205+
* @description The origin server requires the request to be conditional. This response is intended to prevent the 'lost update' problem, where a client GETs a resource's state, modifies it and PUTs it back to the server, when meanwhile a third party has modified the state on the server, leading to a conflict.
194206
*/
195207
PRECONDITION_REQUIRED = 428,
196208
/**
197-
* @description - @
209+
* @description The user has sent too many requests in a given amount of time ("rate limiting").
198210
*/
199211
TOO_MANY_REQUESTS = 429,
200212
/**
201-
* @description - @
213+
* @description The server is unwilling to process the request because its header fields are too large. The request may be resubmitted after reducing the size of the request header fields.
202214
*/
203215
REQUEST_HEADER_FIELDS_TOO_LARGE = 431,
204216
/**
205-
* @description - @
217+
* @description The user agent requested a resource that cannot legally be provided, such as a web page censored by a government.
206218
*/
207219
UNAVAILABLE_FOR_LEGAL_REASONS = 451,
208220
/**

src/StatusDescription/index.ts

Lines changed: 39 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -90,107 +90,119 @@ export enum StatusDescription {
9090
*/
9191
PERMANENT_REDIRECT = "This means that the resource is now permanently located at another URI, specified by the Location: HTTP Response header. This has the same semantics as the 301 Moved Permanently HTTP response code, with the exception that the user agent must not change the HTTP method used: if a POST was used in the first request, a POST must be used in the second request.",
9292
/**
93-
* @description - StatusCode =
93+
* @description - StatusCode = 400
9494
*/
9595
BAD_REQUEST = "The server cannot or will not process the request due to something that is perceived to be a client error (e.g., malformed request syntax, invalid request message framing, or deceptive request routing).",
9696
/**
97-
* @description - StatusCode =
97+
* @description - StatusCode = 401
9898
*/
9999
UNAUTHORIZED = "Although the HTTP standard specifies `unauthorized`, semantically this response means 'unauthenticated'. That is, the client must authenticate itself to get the requested response.",
100100
/**
101-
* @description - StatusCode =
101+
* @description - StatusCode = 402
102102
*/
103103
PAYMENT_REQUIRED = "This response code is reserved for future use. The initial aim for creating this code was using it for digital payment systems, however this status code is used very rarely and no standard convention exists.",
104104
/**
105-
* @description - StatusCode =
105+
* @description - StatusCode = 403
106106
*/
107107
FORBIDDEN = "The client does not have access rights to the content; that is, it is unauthorized, so the server is refusing to give the requested resource. Unlike 401 Unauthorized, the client's identity is known to the server.",
108108
/**
109-
* @description - StatusCode 404
109+
* @description - StatusCode = 404
110110
*/
111111
NOT_FOUND = "The server can not find the requested resource. In the browser, this means the URL is not recognized. In an API, this can also mean that the endpoint is valid but the resource itself does not exist. Servers may also send this response instead of 403 Forbidden to hide the existence of a resource from an unauthorized client. This response code is probably the most well known due to its frequent occurrence on the web.",
112112
/**
113-
* @description - StatusCode =
113+
* @description - StatusCode = 405
114114
*/
115115
METHOD_NOT_ALLOWED = "The request method is known by the server but is not supported by the target resource. For example, an API may not allow calling DELETE to remove a resource.",
116116
/**
117-
* @description - StatusCode =
117+
* @description - StatusCode = 406
118118
*/
119119
NOT_ACCEPTABLE = "This response is sent when the web server, after performing server-driven content negotiation, doesn't find any content that conforms to the criteria given by the user agent.",
120120
/**
121-
* @description - StatusCode =
121+
* @description - StatusCode = 407
122122
*/
123123
PROXY_AUTHENTICATION_REQUIRED = "This is similar to 401 Unauthorized but authentication is needed to be done by a proxy.",
124124
/**
125-
* @description - StatusCode =
125+
* @description - StatusCode = 408
126126
*/
127-
REQUEST_TIMEOUT = "This response is sent on an idle connection by some servers, even without any previous request by the client. It means that the server would like to shut down this unused connection. This response is used much more since some browsers, like Chrome, Firefox 27+, or IE9, use HTTP pre-connection mechanisms to speed up surfing. Also note that some servers merely shut down the connection without sending this message.",
127+
REQUEST_TIMEOUT = "This response is sent on an idle connection by some servers, even without any previous request by the client. It means that the server would like to shut down this unused connection.",
128128
/**
129-
* @description - StatusCode =
129+
* @description - StatusCode = 409
130130
*/
131131
CONFLICT = "This response is sent when a request conflicts with the current state of the server.",
132132
/**
133-
* @description - StatusCode =
133+
* @description - StatusCode = 410
134134
*/
135135
GONE = "This response is sent when the requested content has been permanently deleted from server, with no forwarding address. Clients are expected to remove their caches and links to the resource. The HTTP specification intends this status code to be used for `limited-time, promotional services`. APIs should not feel compelled to indicate resources that have been deleted with this status code.",
136136
/**
137-
* @description - StatusCode =
137+
* @description - StatusCode = 411
138138
*/
139139
LENGTH_REQUIRED = "Server rejected the request because the Content-Length header field is not defined and the server requires it.",
140140
/**
141-
* @description - StatusCode =
141+
* @description - StatusCode = 412
142142
*/
143143
PRECONDITION_FAILED = "The client has indicated preconditions in its headers which the server does not meet.",
144144
/**
145-
* @description - StatusCode =
145+
* @description - StatusCode = 413
146146
*/
147147
PAYLOAD_TOO_LARGE = "Request entity is larger than limits defined by server. The server might close the connection or return an Retry-After header field.",
148148
/**
149-
* @description - StatusCode =
149+
* @description - StatusCode = 414
150150
*/
151151
URI_TOO_LONG = "The URI requested by the client is longer than the server is willing to interpret",
152152
/**
153-
* @description - StatusCode =
153+
* @description - StatusCode = 415
154154
*/
155155
UNSUPPORTED_MEDIA_TYPE = "The media format of the requested data is not supported by the server, so the server is rejecting the request.",
156156
/**
157-
* @description - StatusCode =
157+
* @description - StatusCode = 416
158158
*/
159159
RANGE_NOT_SATISFIABLE = "The range specified by the Range header field in the request cannot be fulfilled. It's possible that the range is outside the size of the target URI's data.",
160160
/**
161-
* @description - StatusCode =
161+
* @description - StatusCode = 417
162162
*/
163163
EXPECTATION_FAILED = "This response code means the expectation indicated by the Expect request header field cannot be met by the server.",
164164
/**
165-
* @description - StatusCode 418
165+
* @description - StatusCode = 418
166166
*/
167167
IM_A_TEAPOT = "The server refuses the attempt to brew coffee with a teapot.",
168168
/**
169-
* @description - StatusCode =
169+
* @description - StatusCode = 421
170+
*/
171+
MISDIRECTED_REQUEST = "The request was directed at a server that is not able to produce a response. This can be sent by a server that is not configured to produce responses for the combination of scheme and authority that are included in the request URI.",
172+
/**
173+
* @description - StatusCode = 422
170174
*/
171175
UNPROCESSABLE_ENTITY = "The request was well-formed but was unable to be followed due to semantic errors.",
172176
/**
173-
* @description - StatusCode =
177+
* @description - StatusCode = 423
178+
*/
179+
LOCKED = "The resource that is being accessed is locked.",
180+
/**
181+
* @description - StatusCode = 424
182+
*/
183+
FAILED_DEPENDENCY = "The request failed due to failure of a previous request.",
184+
/**
185+
* @description - StatusCode = 425
174186
*/
175187
TOO_EARLY = "Indicates that the server is unwilling to risk processing a request that might be replayed.",
176188
/**
177-
* @description - StatusCode =
189+
* @description - StatusCode = 426
178190
*/
179191
UPGRADE_REQUIRED = "The server refuses to perform the request using the current protocol but might be willing to do so after the client upgrades to a different protocol. The server sends an Upgrade header in a 426 response to indicate the required protocol(s).",
180192
/**
181-
* @description - StatusCode =
193+
* @description - StatusCode = 428
182194
*/
183195
PRECONDITION_REQUIRED = "The origin server requires the request to be conditional. This response is intended to prevent the 'lost update' problem, where a client GETs a resource's state, modifies it and PUTs it back to the server, when meanwhile a third party has modified the state on the server, leading to a conflict.",
184196
/**
185-
* @description - StatusCode =
197+
* @description - StatusCode = 429
186198
*/
187199
TOO_MANY_REQUESTS = "The user has sent too many requests in a given amount of time (`rate limiting`).",
188200
/**
189-
* @description - StatusCode =
201+
* @description - StatusCode = 431
190202
*/
191203
REQUEST_HEADER_FIELDS_TOO_LARGE = "The server is unwilling to process the request because its header fields are too large. The request may be resubmitted after reducing the size of the request header fields.",
192204
/**
193-
* @description - StatusCode =
205+
* @description - StatusCode = 451
194206
*/
195207
UNAVAILABLE_FOR_LEGAL_REASONS = "The user agent requested a resource that cannot legally be provided, such as a web page censored by a government.",
196208
/**

src/StatusLabel/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,10 @@ export enum StatusLabel {
4545
RANGE_NOT_SATISFIABLE,
4646
EXPECTATION_FAILED,
4747
IM_A_TEAPOT,
48+
MISDIRECTED_REQUEST,
4849
UNPROCESSABLE_ENTITY,
50+
LOCKED,
51+
FAILED_DEPENDENCY,
4952
TOO_EARLY,
5053
UPGRADE_REQUIRED,
5154
PRECONDITION_REQUIRED,

src/StatusPhrase/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,10 @@ export enum StatusPhrase {
4545
RANGE_NOT_SATISFIABLE = "Range Not Satisfiable",
4646
EXPECTATION_FAILED = "Expectation Failed",
4747
IM_A_TEAPOT = "I'm a teapot",
48+
MISDIRECTED_REQUEST = "Misdirected Request",
4849
UNPROCESSABLE_ENTITY = "Unprocessable Entity",
50+
LOCKED = "Locked",
51+
FAILED_DEPENDENCY = "Failed Dependency",
4952
TOO_EARLY = "Too Early",
5053
UPGRADE_REQUIRED = "Upgrade Required",
5154
PRECONDITION_REQUIRED = "Precondition Required",

tests/helpers.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ import { StatusLabel } from "../src/StatusLabel/";
1212
describe("makeHttpResponsesDictionary tests", () => {
1313
const dictionary = makeHttpResponsesDictionary();
1414

15-
it("should create a dictionary with 58 objects", () => {
16-
expect(Object.entries(dictionary)).toHaveLength(58);
15+
it("should create a dictionary with 61 objects", () => {
16+
expect(Object.entries(dictionary)).toHaveLength(61);
1717
});
1818

1919
it("should assert content from dictionary for an informational response", () => {

0 commit comments

Comments
 (0)