1
0
mirror of https://github.com/fafhrd91/actix-web synced 2024-11-24 08:22:59 +01:00

allow to create response with error message

This commit is contained in:
Nikolay Kim 2018-10-30 11:46:44 -07:00
parent c2540cc59b
commit 148cf73003

View File

@ -98,6 +98,14 @@ impl Error {
Fail::downcast_ref(self.cause.as_fail()); Fail::downcast_ref(self.cause.as_fail());
compat.and_then(|e| e.get_ref().downcast_ref()) compat.and_then(|e| e.get_ref().downcast_ref())
} }
/// Converts error to a response instance and set error message as response body
pub fn response_with_message(self) -> Response {
let message = format!("{}", self);
let mut resp: Response = self.into();
resp.set_body(message);
resp
}
} }
/// Helper trait to downcast a response error into a fail. /// Helper trait to downcast a response error into a fail.