forked from loafle/openapi-generator-original
[go-server] add field name in parsing error messages (#18533)
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.
This commit is contained in:
@@ -23,7 +23,8 @@ var (
|
||||
|
||||
// ParsingError indicates that an error has occurred when parsing request parameters
|
||||
type ParsingError struct {
|
||||
Err error
|
||||
Param string
|
||||
Err error
|
||||
}
|
||||
|
||||
func (e *ParsingError) Unwrap() error {
|
||||
@@ -31,7 +32,11 @@ func (e *ParsingError) Unwrap() error {
|
||||
}
|
||||
|
||||
func (e *ParsingError) Error() string {
|
||||
return e.Err.Error()
|
||||
if e.Param == "" {
|
||||
return e.Err.Error()
|
||||
} else {
|
||||
return e.Param + ": " + e.Err.Error()
|
||||
}
|
||||
}
|
||||
|
||||
// RequiredError indicates that an error has occurred when parsing request parameters
|
||||
|
||||
Reference in New Issue
Block a user