ggicci / httpin

🍡 HTTP Input for Go - HTTP Request from/to Go Struct (Bi-directional Data Binding between Go Struct and http.Request)
https://ggicci.github.io/httpin/
MIT License
315 stars 23 forks source link

How to know which field is wrong if error? #112

Open Crandel opened 1 day ago

Crandel commented 1 day ago

Without exposing InvalidFieldError from core package how to know which query param is wrong, if I need to have custom error message for end user? Even with CustomErrorHandler it still not possible to separate which query param is wrong in case I need to parse many params in the same time and provide simple error message to the end user

For example:

invalid response
got:
   {StatusCode:400 Error:failed to parse request queries: invalid field "ProfileIntegrationID": resolve field "ProfileIntegrationID (string)" failed: execute directive "required" with args [] failed: missing required field}
want:
   {StatusCode:400 Error:failed to parse request queries: could not parse ProfileIntegrationID parameter}

End user should not know anything about some "strange" directives, etc. The only option right now is to parse error message as string.