From 2410896899b29f58c5ca4de5a94cac1c917054ae Mon Sep 17 00:00:00 2001 From: rasul Date: Sun, 2 Feb 2020 16:39:05 -0600 Subject: [PATCH] use create_html_error_response and add create_text_error_response --- src/error_response.rs | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/error_response.rs b/src/error_response.rs index a914355..28adbb7 100644 --- a/src/error_response.rs +++ b/src/error_response.rs @@ -4,6 +4,7 @@ use gotham::helpers::http::response::create_response; use gotham::state::State; use hyper::{Body, Response, StatusCode}; +use log::error; use mime; #[derive(Debug, Template)] @@ -14,7 +15,7 @@ pub struct HtmlError { error_description: String, } -pub fn create_error_response( +pub fn create_html_error_response( status: StatusCode, site_url: String, state: &State, @@ -27,11 +28,18 @@ pub fn create_error_response( match template.render() { Ok(content) => create_response(&state, status, mime::TEXT_HTML_UTF_8, content.into_bytes()), - Err(_) => create_response( - &state, - StatusCode::INTERNAL_SERVER_ERROR, - mime::TEXT_PLAIN, - Body::from("500 INTERNAL SERVER ERROR"), - ), + Err(e) => { + error!("error_response.rs(10): {:?}", e); + create_response( + &state, + StatusCode::INTERNAL_SERVER_ERROR, + mime::TEXT_PLAIN, + Body::from("500 INTERNAL SERVER ERROR"), + ) + } } } + +pub fn create_text_error_response(status: StatusCode, state: &State) -> Response { + create_response(&state, status, mime::TEXT_PLAIN, status.canonical_reason().unwrap_or_default()) +}