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