axum/examples/customize-extractor-error/README.md

17 lines
585 B
Markdown
Raw Normal View History

Extend custom rejection examples (#1276) * examples: Created new `error-handling` example * examples(error-handling): Add error codes and responses * examples(error-handling): `custom_extractor` * examples(error-handling): `derive_from_request` * examples(error-handling): Using POST instead of GET * examples(error-handling): Using `thiserror` for `derive_from_request` * examples(error-handling): Using `snake-case` for routes * revert(error-handling): Use `From` impl instead of `thiserror` refs: 3533d96215ec14db41eb2d4cdd3314c5d10f4f6e * examples(error-handling): Removed chrono * examples: merged `error-handling` and `customize-extractor-error` * examples(customize-extractor-error): Improved error codes * examples(customize-extractor-error): rustfmt * examples(customize-extractor-error): Removed `matched-path` feature Co-authored-by: David Pedersen <david.pdrsn@gmail.com> * examples(customize-extractor-error): added `publish=false` to `Cargo.toml` Co-authored-by: David Pedersen <david.pdrsn@gmail.com> * examples(customize-extractor-error): Fix env filter * examples(customize-extractor-error): Added README * examples(customize-extractor-error): Added `with_rejection` comments * examples(customize-extractor-error): Added `custom_extractor` comments * examples(customize-extractor-error):Typo on `with_rejection` * examples(customize-extractor-error): Added `boilerplate` con to `custom_extractor` * examples(customize-extractor-error): Added `derive_from_request` comments * examples(customize-extractor-error): typo impossible * examples(customize-extractor-error): typos * examples(customize-extractor-error): replaced `extensions` with `extract` * examples(customize-extractor-error): typo `from` Co-authored-by: David Pedersen <david.pdrsn@gmail.com> Co-authored-by: David Pedersen <david.pdrsn@gmail.com>
2022-08-19 15:11:03 +02:00
This example explores 3 different ways you can create custom rejections for
already existing extractors
- [`with_rejection`](src/with_rejection.rs): Uses
`axum_extra::extract::WithRejection` to transform one rejection into another
- [`derive_from_request`](src/derive_from_request.rs): Uses the
`axum::extract::FromRequest` derive macro to wrap another extractor and
customize the rejection
Extend custom rejection examples (#1276) * examples: Created new `error-handling` example * examples(error-handling): Add error codes and responses * examples(error-handling): `custom_extractor` * examples(error-handling): `derive_from_request` * examples(error-handling): Using POST instead of GET * examples(error-handling): Using `thiserror` for `derive_from_request` * examples(error-handling): Using `snake-case` for routes * revert(error-handling): Use `From` impl instead of `thiserror` refs: 3533d96215ec14db41eb2d4cdd3314c5d10f4f6e * examples(error-handling): Removed chrono * examples: merged `error-handling` and `customize-extractor-error` * examples(customize-extractor-error): Improved error codes * examples(customize-extractor-error): rustfmt * examples(customize-extractor-error): Removed `matched-path` feature Co-authored-by: David Pedersen <david.pdrsn@gmail.com> * examples(customize-extractor-error): added `publish=false` to `Cargo.toml` Co-authored-by: David Pedersen <david.pdrsn@gmail.com> * examples(customize-extractor-error): Fix env filter * examples(customize-extractor-error): Added README * examples(customize-extractor-error): Added `with_rejection` comments * examples(customize-extractor-error): Added `custom_extractor` comments * examples(customize-extractor-error):Typo on `with_rejection` * examples(customize-extractor-error): Added `boilerplate` con to `custom_extractor` * examples(customize-extractor-error): Added `derive_from_request` comments * examples(customize-extractor-error): typo impossible * examples(customize-extractor-error): typos * examples(customize-extractor-error): replaced `extensions` with `extract` * examples(customize-extractor-error): typo `from` Co-authored-by: David Pedersen <david.pdrsn@gmail.com> Co-authored-by: David Pedersen <david.pdrsn@gmail.com>
2022-08-19 15:11:03 +02:00
- [`custom_extractor`](src/custom_extractor.rs): Manual implementation of
`FromRequest` that wraps another extractor
Run with
```sh
cargo run -p example-customize-extractor-error
Extend custom rejection examples (#1276) * examples: Created new `error-handling` example * examples(error-handling): Add error codes and responses * examples(error-handling): `custom_extractor` * examples(error-handling): `derive_from_request` * examples(error-handling): Using POST instead of GET * examples(error-handling): Using `thiserror` for `derive_from_request` * examples(error-handling): Using `snake-case` for routes * revert(error-handling): Use `From` impl instead of `thiserror` refs: 3533d96215ec14db41eb2d4cdd3314c5d10f4f6e * examples(error-handling): Removed chrono * examples: merged `error-handling` and `customize-extractor-error` * examples(customize-extractor-error): Improved error codes * examples(customize-extractor-error): rustfmt * examples(customize-extractor-error): Removed `matched-path` feature Co-authored-by: David Pedersen <david.pdrsn@gmail.com> * examples(customize-extractor-error): added `publish=false` to `Cargo.toml` Co-authored-by: David Pedersen <david.pdrsn@gmail.com> * examples(customize-extractor-error): Fix env filter * examples(customize-extractor-error): Added README * examples(customize-extractor-error): Added `with_rejection` comments * examples(customize-extractor-error): Added `custom_extractor` comments * examples(customize-extractor-error):Typo on `with_rejection` * examples(customize-extractor-error): Added `boilerplate` con to `custom_extractor` * examples(customize-extractor-error): Added `derive_from_request` comments * examples(customize-extractor-error): typo impossible * examples(customize-extractor-error): typos * examples(customize-extractor-error): replaced `extensions` with `extract` * examples(customize-extractor-error): typo `from` Co-authored-by: David Pedersen <david.pdrsn@gmail.com> Co-authored-by: David Pedersen <david.pdrsn@gmail.com>
2022-08-19 15:11:03 +02:00
```