Single-binary self-hosted Markdown blog on Rust axum: no database, live search, Typst PDF export, and strong SEO.
axumblogdockermarkdownminijinjarustself-hostedtypstvite
1use axum::http::StatusCode;
2use axum::response::{IntoResponse, Response};
3
4pub struct AppError(pub StatusCode, pub String);
5
6impl AppError {
7 pub fn not_found() -> Self {
8 AppError(StatusCode::NOT_FOUND, "not found".to_string())
9 }
10}
11
12impl<E: std::fmt::Display> From<E> for AppError {
13 fn from(e: E) -> Self {
14 // Log the detail, serve a generic body: template and IO error strings
15 // can leak paths and internals to the client.
16 tracing::error!("internal error: {e}");
17 AppError(
18 StatusCode::INTERNAL_SERVER_ERROR,
19 "internal server error".to_string(),
20 )
21 }
22}
23
24impl IntoResponse for AppError {
25 fn into_response(self) -> Response {
26 (self.0, self.1).into_response()
27 }
28}