-
Notifications
You must be signed in to change notification settings - Fork 558
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
Adding serde_json::Error::code() functionnality #865
base: master
Are you sure you want to change the base?
Conversation
I've taken the errors into account and will release a fix soon. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be fixed now.
EDIT: nevermind there are still a bug with older version of rust
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed now 👍
Any update on the feature ? |
Could this PR be considered for review? It seems quite important to be able to extract some information about the specific error that occurs during deserialization. To give an example, for deserialising POST request bodies, when deserialization fails it would be nice to be able to provide meaningful errors in a 400 response explaining why the body is not formed correctly. Doing validation (regex/min lengths etc.) after a successful deserialization is possible, but when deserialization fails it's quite difficult to build an appropriate error message from just the |
Hi,
With this commit, I'm trying to add the ability to identify the precise error that occurred during de/serialization. There should be no breaking change and a new method serde_json::Error::Code() now exposes the internal code of the error.
The original purpose is to provide translated information on the error (for API body request validation for example) as well as handling errors more precisely.
It is not yet perfect as serde injects some data (eg. https://github.com/serde-rs/serde) and changing this behavior would probably be breaking.
A simple example of the new functionality would be :