Docs improvements (#37)

This commit is contained in:
David Pedersen
2021-07-22 15:00:33 +02:00
committed by GitHub
parent a658c94f23
commit 8faed8120f
11 changed files with 263 additions and 291 deletions
+7 -6
View File
@@ -19,6 +19,7 @@ use http::StatusCode;
use std::{
borrow::Cow,
collections::HashMap,
convert::Infallible,
net::SocketAddr,
sync::{Arc, RwLock},
time::Duration,
@@ -152,20 +153,20 @@ where
}
}
fn handle_error(error: BoxError) -> impl IntoResponse {
fn handle_error(error: BoxError) -> Result<impl IntoResponse, Infallible> {
if error.is::<tower::timeout::error::Elapsed>() {
return (StatusCode::REQUEST_TIMEOUT, Cow::from("request timed out"));
return Ok((StatusCode::REQUEST_TIMEOUT, Cow::from("request timed out")));
}
if error.is::<tower::load_shed::error::Overloaded>() {
return (
return Ok((
StatusCode::SERVICE_UNAVAILABLE,
Cow::from("service is overloaded, try again later"),
);
));
}
(
Ok((
StatusCode::INTERNAL_SERVER_ERROR,
Cow::from(format!("Unhandled internal error: {}", error)),
)
))
}
+2 -2
View File
@@ -10,10 +10,10 @@ async fn main() {
let app = axum::routing::nest(
"/static",
axum::service::get(ServeDir::new(".").handle_error(|error: std::io::Error| {
(
Ok::<_, std::convert::Infallible>((
StatusCode::INTERNAL_SERVER_ERROR,
format!("Unhandled interal error: {}", error),
)
))
})),
)
.layer(TraceLayer::new_for_http());
+2 -2
View File
@@ -33,10 +33,10 @@ async fn main() {
ServeDir::new("examples/websocket")
.append_index_html_on_directories(true)
.handle_error(|error: std::io::Error| {
(
Ok::<_, std::convert::Infallible>((
StatusCode::INTERNAL_SERVER_ERROR,
format!("Unhandled interal error: {}", error),
)
))
}),
),
)