daoyi_cloud_common/common_hoops/
mod.rs

1use askama::Template;
2use salvo::http::ResBody;
3use salvo::prelude::*;
4
5pub mod custom_middleware_example;
6pub mod jwt;
7pub use jwt::auth_hoop;
8mod cors;
9pub use cors::cors_hoop;
10
11#[derive(Template)]
12#[template(path = "error_404.html")]
13struct Error404 {
14    brief: String,
15}
16
17#[handler]
18pub async fn error_404(&self, res: &mut Response, ctrl: &mut FlowCtrl) {
19    if let Some(StatusCode::NOT_FOUND) = res.status_code {
20        let handle404 = Error404 {
21            brief: if let ResBody::Error(e) = &res.body {
22                e.brief.clone()
23            } else {
24                "Page not found".to_owned()
25            },
26        };
27        res.render(Text::Html(handle404.render().unwrap()));
28        ctrl.skip_rest();
29    }
30}