@@ -163,31 +163,103 @@ impl Then {
163
163
self
164
164
}
165
165
166
+ /// 200 Ok
166
167
pub fn ok ( self ) -> Self {
167
168
self . update ( |r| {
168
169
r. status = StatusCode :: OK ;
169
170
} ) ;
170
171
self
171
172
}
172
173
174
+ // Common client errors
175
+
176
+ /// 400 Bad Request
177
+ pub fn bad_request ( self ) -> Self {
178
+ self . update ( |r| {
179
+ r. status = StatusCode :: BAD_REQUEST ;
180
+ } ) ;
181
+ self
182
+ }
183
+
184
+ /// 401 Unauthorized
185
+ pub fn unauthorized ( self ) -> Self {
186
+ self . update ( |r| {
187
+ r. status = StatusCode :: UNAUTHORIZED ;
188
+ } ) ;
189
+ self
190
+ }
191
+
192
+ /// 403 Forbidden
193
+ pub fn forbidden ( self ) -> Self {
194
+ self . update ( |r| {
195
+ r. status = StatusCode :: FORBIDDEN ;
196
+ } ) ;
197
+ self
198
+ }
199
+
200
+ /// 404 Not Found
173
201
pub fn not_found ( self ) -> Self {
174
202
self . update ( |r| {
175
203
r. status = StatusCode :: NOT_FOUND ;
176
204
} ) ;
177
205
self
178
206
}
179
207
180
- pub fn bad_request ( self ) -> Self {
208
+ /// 415 Unsupported Media Type
209
+ pub fn unsupported_media_type ( self ) -> Self {
181
210
self . update ( |r| {
182
- r. status = StatusCode :: BAD_REQUEST ;
211
+ r. status = StatusCode :: UNSUPPORTED_MEDIA_TYPE ;
212
+ } ) ;
213
+ self
214
+ }
215
+
216
+ /// 422 Unprocessable Content
217
+ pub fn unprocessable_content ( self ) -> Self {
218
+ self . update ( |r| {
219
+ r. status = StatusCode :: UNPROCESSABLE_ENTITY ;
183
220
} ) ;
184
221
self
185
222
}
186
223
224
+ // Common server errors
225
+
226
+ /// 500 Internal Server Error
187
227
pub fn internal_server_error ( self ) -> Self {
188
228
self . update ( |r| {
189
229
r. status = StatusCode :: INTERNAL_SERVER_ERROR ;
190
230
} ) ;
191
231
self
192
232
}
233
+
234
+ /// 501 Not Implemented
235
+ pub fn not_implemented ( self ) -> Self {
236
+ self . update ( |r| {
237
+ r. status = StatusCode :: NOT_IMPLEMENTED ;
238
+ } ) ;
239
+ self
240
+ }
241
+
242
+ /// 502 Bad Gateway
243
+ pub fn bad_gateway ( self ) -> Self {
244
+ self . update ( |r| {
245
+ r. status = StatusCode :: BAD_GATEWAY ;
246
+ } ) ;
247
+ self
248
+ }
249
+
250
+ /// 503 Service Unavailable
251
+ pub fn service_unavailable ( self ) -> Self {
252
+ self . update ( |r| {
253
+ r. status = StatusCode :: SERVICE_UNAVAILABLE ;
254
+ } ) ;
255
+ self
256
+ }
257
+
258
+ /// 504 Gateway Timeout
259
+ pub fn gateway_timeout ( self ) -> Self {
260
+ self . update ( |r| {
261
+ r. status = StatusCode :: GATEWAY_TIMEOUT ;
262
+ } ) ;
263
+ self
264
+ }
193
265
}
0 commit comments