From 148cf73003c10728b773d3d0fd6256c4ff6016f1 Mon Sep 17 00:00:00 2001 From: Nikolay Kim Date: Tue, 30 Oct 2018 11:46:44 -0700 Subject: [PATCH] allow to create response with error message --- src/error.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/error.rs b/src/error.rs index 3c090203..3064cda4 100644 --- a/src/error.rs +++ b/src/error.rs @@ -98,6 +98,14 @@ impl Error { Fail::downcast_ref(self.cause.as_fail()); 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.