mirror of
https://github.com/tokio-rs/axum.git
synced 2026-08-27 00:00:24 +02:00
docs: Add links to more examples of Result-returning handlers. (#2049)
Co-authored-by: David Pedersen <[email protected]>
This commit is contained in:
co-authored by
David Pedersen
parent
652d65aabc
commit
8dae97a5e8
@@ -38,6 +38,16 @@ It doesn't matter whether you return `Err(StatusCode::NOT_FOUND)` or
|
|||||||
`Err(StatusCode::INTERNAL_SERVER_ERROR)`. These are not considered errors in
|
`Err(StatusCode::INTERNAL_SERVER_ERROR)`. These are not considered errors in
|
||||||
axum.
|
axum.
|
||||||
|
|
||||||
|
Instead of a direct `StatusCode`, it makes sense to use intermediate error type
|
||||||
|
that can ultimately be converted to `Reponse`. This allows using `?` operator
|
||||||
|
in handlers. See those examples:
|
||||||
|
|
||||||
|
* [`anyhow-error-response`][anyhow] for generic boxed errors
|
||||||
|
* [`error-handling-and-dependency-injection`][ehdi] for application-specific detailed errors
|
||||||
|
|
||||||
|
[anyhow]:https://github.com/tokio-rs/axum/blob/main/examples/anyhow-error-response/src/main.rs
|
||||||
|
[ehdi]:https://github.com/tokio-rs/axum/blob/main/examples/error-handling-and-dependency-injection/src/main.rs
|
||||||
|
|
||||||
This also applies to extractors. If an extractor doesn't match the request the
|
This also applies to extractors. If an extractor doesn't match the request the
|
||||||
request will be rejected and a response will be returned without calling your
|
request will be rejected and a response will be returned without calling your
|
||||||
handler. See [`extract`](crate::extract) to learn more about handling extractor
|
handler. See [`extract`](crate::extract) to learn more about handling extractor
|
||||||
|
|||||||
@@ -32,6 +32,16 @@
|
|||||||
//! }
|
//! }
|
||||||
//! ```
|
//! ```
|
||||||
//!
|
//!
|
||||||
|
//! Instead of a direct `StatusCode`, it makes sense to use intermediate error type
|
||||||
|
//! that can ultimately be converted to `Reponse`. This allows using `?` operator
|
||||||
|
//! in handlers. See those examples:
|
||||||
|
//!
|
||||||
|
//! * [`anyhow-error-response`][anyhow] for generic boxed errors
|
||||||
|
//! * [`error-handling-and-dependency-injection`][ehdi] for application-specific detailed errors
|
||||||
|
//!
|
||||||
|
//! [anyhow]:https://github.com/tokio-rs/axum/blob/main/examples/anyhow-error-response/src/main.rs
|
||||||
|
//! [ehdi]:https://github.com/tokio-rs/axum/blob/main/examples/error-handling-and-dependency-injection/src/main.rs
|
||||||
|
//!
|
||||||
#![doc = include_str!("../docs/debugging_handler_type_errors.md")]
|
#![doc = include_str!("../docs/debugging_handler_type_errors.md")]
|
||||||
|
|
||||||
#[cfg(feature = "tokio")]
|
#[cfg(feature = "tokio")]
|
||||||
|
|||||||
Reference in New Issue
Block a user