sword_layers/
not_found.rs1use crate::ResponseFnMapper;
2use axum::{
3 http::StatusCode,
4 response::{IntoResponse, Response},
5};
6use axum_responses::JsonResponse;
7use tower::{ServiceBuilder, util::MapResponseLayer};
8use tower_layer::{Identity, Stack};
9
10pub struct NotFoundLayer;
11
12pub type ResponseFnMapperServiceLayer =
13 ServiceBuilder<Stack<MapResponseLayer<ResponseFnMapper>, Identity>>;
14
15impl NotFoundLayer {
16 pub fn new() -> ResponseFnMapperServiceLayer {
17 ServiceBuilder::new().map_response(|r: Response| {
18 if r.status() != StatusCode::NOT_FOUND {
19 return r;
20 }
21
22 JsonResponse::NotFound()
23 .message("The requested resource was not found.")
24 .into_response()
25 })
26 }
27}