axum_route_error/
route_internal_error.rs1use super::RouteError;
2
3pub type RouteInternalError<S = ()> = RouteError<S, true>;
7
8#[cfg(test)]
9mod test_route_internal_error {
10 use super::*;
11 use crate::RouteErrorOutput;
12 use anyhow::anyhow;
13 use axum::response::IntoResponse;
14 use http_body_util::BodyExt;
15 use serde_json::from_slice;
16
17 #[tokio::test]
18 async fn it_should_output_internal_error() {
19 fn raise_error() -> Result<(), RouteInternalError> {
20 Err(anyhow!("Too many foxes in the DB"))?;
21
22 Ok(())
23 }
24
25 let err = raise_error().unwrap_err();
26 let response = err.into_response();
27 let response_body = response.into_body();
28 let response_bytes = response_body.collect().await.unwrap().to_bytes();
29 let body = from_slice::<RouteErrorOutput<()>>(&response_bytes).unwrap();
30
31 assert_eq!(
32 body.internal_error.unwrap().name,
33 "Too many foxes in the DB"
34 );
35 }
36}