1use crate::view::render;
7use axum::{
8 http::StatusCode,
9 response::IntoResponse,
10};
11use minijinja::context;
12
13pub struct ErrorController;
14
15impl ErrorController {
16 pub fn show(code: u16, message: &str) -> impl IntoResponse {
18 let status = StatusCode::from_u16(code).unwrap_or(StatusCode::INTERNAL_SERVER_ERROR);
19
20 let title = match code {
21 401 => "Unauthorized",
22 402 => "Payment Required",
23 403 => "Forbidden",
24 404 => "Page Not Found",
25 419 => "Page Expired",
26 429 => "Too Many Requests",
27 500 => "Server Error",
28 503 => "Service Unavailable",
29 _ => "Error",
30 };
31
32 (status, render("errors/minimal.rb.html", context! {
33 code => code,
34 title => title,
35 message => message
36 }))
37 }
38
39 pub async fn not_found() -> impl IntoResponse {
41 Self::show(404, "Maaf, halaman yang Anda cari tidak ditemukan.")
42 }
43}