parent
5401bcc268
commit
51f458fb1a
@ -0,0 +1,37 @@
|
||||
use askama::Template;
|
||||
|
||||
use gotham::helpers::http::response::create_response;
|
||||
use gotham::state::State;
|
||||
|
||||
use hyper::{Body, Response, StatusCode};
|
||||
use mime;
|
||||
|
||||
#[derive(Debug, Template)]
|
||||
#[template(path = "error.html")]
|
||||
pub struct HtmlError {
|
||||
site_url: String,
|
||||
error_number: u16,
|
||||
error_description: String,
|
||||
}
|
||||
|
||||
pub fn create_error_response(
|
||||
status: StatusCode,
|
||||
site_url: String,
|
||||
state: &State,
|
||||
) -> Response<Body> {
|
||||
let template = HtmlError {
|
||||
site_url,
|
||||
error_number: status.as_u16(),
|
||||
error_description: status.canonical_reason().unwrap_or("").into(),
|
||||
};
|
||||
|
||||
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"),
|
||||
),
|
||||
}
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>pastebucket :: error</title>
|
||||
<link rel="stylesheet" href="/s/pastebucket.css">
|
||||
</head>
|
||||
<body>
|
||||
<header>
|
||||
<h1><a href="{{site_url|safe}}">pastebucket</a></h1>
|
||||
<hr>
|
||||
</header>
|
||||
<main>
|
||||
<div class="error">
|
||||
<div class="error_number">{{error_number}}</div>
|
||||
<div class="error_description">{{error_description}}</div>
|
||||
</div>
|
||||
</main>
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in new issue