Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

create a set of custom extractors for better error responses #1097

Open
jondot opened this issue Dec 22, 2024 · 0 comments
Open

create a set of custom extractors for better error responses #1097

jondot opened this issue Dec 22, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@jondot
Copy link
Contributor

jondot commented Dec 22, 2024

Today all Axum extractors (Json, etc), upon an error action (e.g. in case of Json, malformed JSON), will return what Axum thinks is best practice (usually what they think is the best error code and textual response if any).

With Loco, we'd like to customize it in a way that the shape or amount of information is different.
The technical way to do this with Axum is to create a "wrapper" extractor with the custom error logic, like here.

This means we need to create an array of all of the most used / available extractors and offer these instead of users using the Axum extractors direct.

Implementing the wrapper extractor
Once we're in the wrapper extractor, we need to:

  • let the original extractor do most of the heavy lifting
  • shape the original error into a suitable loco_rs::Error, whether it is a validation error or something else

On the way out, in the "into response" conversion, we need to set the shape of the error the user will see, and decide if we want to expose the details public or not.

The mapping between: Extractor <> Extractor Error space <> Loco error space <> public http shape is not spec'd yet and is more of a conceptual issue that needs to be researched first.

@jondot jondot added the enhancement New feature or request label Dec 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant