[go-server] add field name in parsing error messages#18533
Merged
wing328 merged 1 commit intoOpenAPITools:masterfrom May 1, 2024
Merged
[go-server] add field name in parsing error messages#18533wing328 merged 1 commit intoOpenAPITools:masterfrom
wing328 merged 1 commit intoOpenAPITools:masterfrom
Conversation
Contributor
Author
Contributor
|
It would be better if the errors were wrapped, instead of passing the name into the function. fmt.Errorf(“param name: %w” err) there’s also nested ParsingError which we might want to remove. I think the error handling in this quite old before the error wrapping came out |
Currently when a parsing rule of a field is not respected (eg: min/max value, required, ...), the api only returns an error message without providing the field name to help the user to fix the request. This commit add the field name to the error message to help the user of the API.
b648053 to
bf0fe55
Compare
Contributor
Author
|
Actually, I changed a bit the way to do it to add a Param field to ErrParsing so it can apply to all parsing error (eg: WithRequire, WithParse, ...). So the original error is kept. Let me know if it looks better to you. |
Contributor
|
Yes it looks good. Let me take a deeper look and approve it tmr |
5 tasks
Contributor
|
Lgtm. I’ll update the error handler with errors.As() to ensure errors are handled correctly in another PR |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Currently when a min/max value for a number field is not respected, the api only returns a generic error message without providing any useful information to fix the request. This commit add the field name to the error message to help the user of the API.