error handling after using BindUri function (golang)

Viewed 45

I am developing rest api in golang. used the BindUri function and handled the error as follows.

if err := c.BindUri(req); err != nil {
    c.AbortWithError(http.StatusBadRequest, fmt.Errorf("Failed data binding, %v", err))
    return
}

The BindUri function was implemented as follows.

func (c *Context) BindUri(obj interface{}) error {
    if err := c.ShouldBindUri(obj); err != nil {
        c.AbortWithError(http.StatusBadRequest, err).SetType(ErrorTypeBind) // nolint: errcheck
        return err
    }
    return nil 
}

After using the BindUri function, I wanna knows how to properly handle the related error.

0 Answers
Related