mirror of https://github.com/rwf2/Rocket.git
Return 422 for semantically bad Json, MessagePack.
This commit is contained in:
parent
c45a83897f
commit
1c70df052c
|
@ -181,7 +181,11 @@ impl<'r, T: Deserialize<'r>> FromData<'r> for Json<T> {
|
|||
Err(JsonError::Io(e)) if e.kind() == io::ErrorKind::UnexpectedEof => {
|
||||
Outcome::Failure((Status::PayloadTooLarge, JsonError::Io(e)))
|
||||
},
|
||||
Err(JsonError::Parse(s, e)) if e.classify() == serde_json::error::Category::Data => {
|
||||
Outcome::Failure((Status::UnprocessableEntity, JsonError::Parse(s, e)))
|
||||
},
|
||||
Err(e) => Outcome::Failure((Status::BadRequest, e)),
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -167,6 +167,12 @@ impl<'r, T: Deserialize<'r>> FromData<'r> for MsgPack<T> {
|
|||
Err(Error::InvalidDataRead(e)) if e.kind() == io::ErrorKind::UnexpectedEof => {
|
||||
Outcome::Failure((Status::PayloadTooLarge, Error::InvalidDataRead(e)))
|
||||
},
|
||||
| Err(e@Error::TypeMismatch(_))
|
||||
| Err(e@Error::OutOfRange)
|
||||
| Err(e@Error::LengthMismatch(_))
|
||||
=> {
|
||||
Outcome::Failure((Status::UnprocessableEntity, e))
|
||||
},
|
||||
Err(e) => Outcome::Failure((Status::BadRequest, e)),
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue