Skip to content

Commit b41084b

Browse files
committed
Add 422 UnprocessableEntity to StatusCode.
I'm using the surf alpha to talk to an API that returns a 422 when it receives a payload of valid JSON that doesn't match it's expected schema. http-types doesn't know about this status code so surf panics. This adds the 422 status code to http-types to work around this. Would be good if surf didn't panic when receving an unknown status code, though suppose that's a separate issue.
1 parent 12a88c5 commit b41084b

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/status_code.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,11 @@ pub enum StatusCode {
260260
/// and authority that are included in the request URI.
261261
MisdirectedRequest = 421,
262262

263+
/// 422 Unprocessable Entity
264+
///
265+
/// The request was well-formed but was unable to be followed due to semantic errors.
266+
UnprocessableEntity = 422,
267+
263268
/// 425 Too Early
264269
///
265270
/// Indicates that the server is unwilling to risk processing a request that might be replayed.
@@ -441,6 +446,7 @@ impl StatusCode {
441446
StatusCode::ExpectationFailed => "Expectation Failed",
442447
StatusCode::ImATeapot => "I'm a teapot",
443448
StatusCode::MisdirectedRequest => "Misdirected Request",
449+
StatusCode::UnprocessableEntity => "Unprocessable Entity",
444450
StatusCode::TooEarly => "Too Early",
445451
StatusCode::UpgradeRequired => "Upgrade Required",
446452
StatusCode::PreconditionRequired => "Precondition Required",
@@ -509,6 +515,7 @@ impl std::convert::TryFrom<u16> for StatusCode {
509515
417 => Ok(StatusCode::ExpectationFailed),
510516
418 => Ok(StatusCode::ImATeapot),
511517
421 => Ok(StatusCode::MisdirectedRequest),
518+
422 => Ok(StatusCode::UnprocessableEntity),
512519
425 => Ok(StatusCode::TooEarly),
513520
426 => Ok(StatusCode::UpgradeRequired),
514521
428 => Ok(StatusCode::PreconditionRequired),

0 commit comments

Comments
 (0)