use create_html_error_response and add create_text_error_response

master
rasul 5 years ago
parent 8ed7d987d0
commit 2410896899

@ -4,6 +4,7 @@ use gotham::helpers::http::response::create_response;
use gotham::state::State; use gotham::state::State;
use hyper::{Body, Response, StatusCode}; use hyper::{Body, Response, StatusCode};
use log::error;
use mime; use mime;
#[derive(Debug, Template)] #[derive(Debug, Template)]
@ -14,7 +15,7 @@ pub struct HtmlError {
error_description: String, error_description: String,
} }
pub fn create_error_response( pub fn create_html_error_response(
status: StatusCode, status: StatusCode,
site_url: String, site_url: String,
state: &State, state: &State,
@ -27,11 +28,18 @@ pub fn create_error_response(
match template.render() { match template.render() {
Ok(content) => create_response(&state, status, mime::TEXT_HTML_UTF_8, content.into_bytes()), Ok(content) => create_response(&state, status, mime::TEXT_HTML_UTF_8, content.into_bytes()),
Err(_) => create_response( Err(e) => {
error!("error_response.rs(10): {:?}", e);
create_response(
&state, &state,
StatusCode::INTERNAL_SERVER_ERROR, StatusCode::INTERNAL_SERVER_ERROR,
mime::TEXT_PLAIN, mime::TEXT_PLAIN,
Body::from("500 INTERNAL SERVER ERROR"), Body::from("500 INTERNAL SERVER ERROR"),
), )
} }
}
}
pub fn create_text_error_response(status: StatusCode, state: &State) -> Response<Body> {
create_response(&state, status, mime::TEXT_PLAIN, status.canonical_reason().unwrap_or_default())
} }

Loading…
Cancel
Save