openapi-generator icon indicating copy to clipboard operation
openapi-generator copied to clipboard

[go-server] add field name in parsing error messages

Open rledisez opened this issue 9 months ago • 4 comments

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.

rledisez avatar Apr 29 '24 11:04 rledisez

Try to be more user friendly on error messages

Any feedbacks appreciated @antihax @grokify @kemokemo @jirikuncar @ph4r5h4d @lwj5

rledisez avatar Apr 29 '24 12:04 rledisez

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

lwj5 avatar Apr 30 '24 01:04 lwj5

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.

rledisez avatar Apr 30 '24 09:04 rledisez

Yes it looks good. Let me take a deeper look and approve it tmr

lwj5 avatar Apr 30 '24 16:04 lwj5

Lgtm. I’ll update the error handler with errors.As() to ensure errors are handled correctly in another PR

lwj5 avatar May 01 '24 11:05 lwj5