26 lines
673 B
Rust
26 lines
673 B
Rust
use askama::Template;
|
|
use axum::http::StatusCode;
|
|
use axum::response::{Html, IntoResponse, Response};
|
|
|
|
pub struct TemplatedHtml<T>(pub T);
|
|
|
|
impl<T> IntoResponse for TemplatedHtml<T>
|
|
where
|
|
T: Template,
|
|
{
|
|
fn into_response(self) -> Response {
|
|
match self.0.render() {
|
|
Ok(html) => Html(html).into_response(),
|
|
Err(err) => (
|
|
StatusCode::INTERNAL_SERVER_ERROR,
|
|
format!("Failed to render template. Error: {}", err),
|
|
)
|
|
.into_response(),
|
|
}
|
|
}
|
|
}
|
|
|
|
pub fn internal_error(err: anyhow::Error) -> (StatusCode, String) {
|
|
(StatusCode::INTERNAL_SERVER_ERROR, err.to_string())
|
|
}
|