mirror of https://github.com/rwf2/Rocket.git
Add a bad_request response type. Use it when form's aren't utf8.
This commit is contained in:
parent
650d079b58
commit
639a78a8d6
|
@ -94,7 +94,7 @@ impl RouteGenerateExt for RouteParams {
|
|||
let expr = quote_expr!(ecx,
|
||||
match ::std::str::from_utf8(_req.data.as_slice()) {
|
||||
Ok(s) => s,
|
||||
Err(_) => return ::rocket::Response::server_error()
|
||||
Err(_) => return ::rocket::Response::bad_request("form isn't utf8")
|
||||
}
|
||||
);
|
||||
|
||||
|
|
|
@ -52,9 +52,15 @@ impl<'a> Response<'a> {
|
|||
Response(Box::new(Empty::new(StatusCode::NotFound)))
|
||||
}
|
||||
|
||||
pub fn server_error() -> Response<'a> {
|
||||
pub fn server_error(reason: &str) -> Response<'a> {
|
||||
warn_!("internal server error: {}", reason);
|
||||
Response(Box::new(Empty::new(StatusCode::InternalServerError)))
|
||||
}
|
||||
|
||||
pub fn bad_request(reason: &str) -> Response<'a> {
|
||||
warn_!("bad request from user: {}", reason);
|
||||
Response(Box::new(Empty::new(StatusCode::BadRequest)))
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Deref for Response<'a> {
|
||||
|
|
Loading…
Reference in New Issue