-
Notifications
You must be signed in to change notification settings - Fork 8.1k
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
implement ".Unwrap() error" on Error type #2525
Comments
A more useful use case was asked by this user on StackOverflow : He wants to tell apart "this is a JSON parsing error" from "the JSON is ok, this is a validation error" With the correct implementation of the // gErr is a gin.Error
var jsErr *json.UnmarshalTypeError
if errors.As(gErr, &jsErr) {
fmt.Println("the json is invalid")
} else {
fmt.Println("this is something else")
} |
It would also help for other issues for other data types such as trying to un parse an invalid time.Time. in such case it wouldn't return a json parsing error but a time parsing error. |
Co-authored-by: Bo-Yi Wu <[email protected]> Co-authored-by: thinkerou <[email protected]>
#2526 merged |
@thejdavid wrote:
Ya, it seems that even under 1.7.1 there's still no useful information regarding where in a JSON POST the
Hoping it would say |
Description
The 'Error' type defined in errors.go does not implement ".Unwrap() error", which prevents the usage of "errors.Is()" and "errors.As()"
How to reproduce
Expectations
output :
Actual result
no output
Environment
The text was updated successfully, but these errors were encountered: