mirror of
https://github.com/tokio-rs/axum.git
synced 2024-12-27 23:10:20 +01:00
Add Customizing extractor responses
section to docs (#359)
Should make the example easier easier to find for some.
This commit is contained in:
parent
f8154a088c
commit
038c17a514
1 changed files with 15 additions and 0 deletions
15
src/lib.rs
15
src/lib.rs
|
@ -15,6 +15,7 @@
|
|||
//! - [Common extractors](#common-extractors)
|
||||
//! - [Applying multiple extractors](#applying-multiple-extractors)
|
||||
//! - [Optional extractors](#optional-extractors)
|
||||
//! - [Customizing extractor responses](#customizing-extractor-responses)
|
||||
//! - [Building responses](#building-responses)
|
||||
//! - [Applying middleware](#applying-middleware)
|
||||
//! - [To individual handlers](#to-individual-handlers)
|
||||
|
@ -631,6 +632,19 @@
|
|||
//! # };
|
||||
//! ```
|
||||
//!
|
||||
//! ## Customizing extractor responses
|
||||
//!
|
||||
//! If an extractor fails it will return a response with the error and your
|
||||
//! handler will not be called. To customize the error response you have a two
|
||||
//! options:
|
||||
//!
|
||||
//! 1. Use `Result<T, T::Rejection>` as your extractor like shown in ["Optional
|
||||
//! extractors"](#optional-extractors). This works well if you're only using
|
||||
//! the extractor in a single handler.
|
||||
//! 2. Create your own extractor that in its [`FromRequest`] implementing calls
|
||||
//! one of axum's built in extractors but returns a different response for
|
||||
//! rejections. See the [customize-extractor-error] example for more details.
|
||||
//!
|
||||
//! # Building responses
|
||||
//!
|
||||
//! Anything that implements [`IntoResponse`](response::IntoResponse) can be
|
||||
|
@ -1132,6 +1146,7 @@
|
|||
//! [`FromRequest`]: crate::extract::FromRequest
|
||||
//! [`HeaderMap`]: http::header::HeaderMap
|
||||
//! [`Request`]: http::Request
|
||||
//! [customize-extractor-error]: https://github.com/tokio-rs/axum/blob/main/examples/customize-extractor-error/src/main.rs
|
||||
|
||||
#![warn(
|
||||
clippy::all,
|
||||
|
|
Loading…
Reference in a new issue