Skip to content

Return the original error when binding a json payload #888

Closed
@rv-rsouza

Description

@rv-rsouza

I need to treat some binding errors, like invalid time format when unmarshaling json from the payload.

It wold be nice to have a property on the echo.HTTPError with the original error reference. Something like InnerError (inner exception, as in .Net) or OriginalError.

This would be useful to know what caused the HTTPError aside from looking at the error message. Eg:

var myType MyType
err := c.Bind(&myType)
if err != nil {
    if parseError, ok := err.OriginalError.(json.UnmarshalTypeError); ok {
        fmt.Println("Error parsing field:", parseError.Field)
    }
    // ...
}
// ...

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions