use json.Marshal provided with validation
This commit is contained in:
parent
cd7d44fcd8
commit
2d7f6be830
5 changed files with 40 additions and 56 deletions
|
|
@ -2,6 +2,7 @@ package app
|
|||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
|
||||
"github.com/dhax/go-base/auth/jwt"
|
||||
|
|
@ -11,6 +12,11 @@ import (
|
|||
validation "github.com/go-ozzo/ozzo-validation"
|
||||
)
|
||||
|
||||
// The list of error types returned from account resource.
|
||||
var (
|
||||
ErrProfileValidation = errors.New("profile validation error")
|
||||
)
|
||||
|
||||
// ProfileStore defines database operations for a profile.
|
||||
type ProfileStore interface {
|
||||
Get(accountID int) (*models.Profile, error)
|
||||
|
|
@ -85,7 +91,7 @@ func (rs *ProfileResource) update(w http.ResponseWriter, r *http.Request) {
|
|||
if err := rs.Store.Update(p); err != nil {
|
||||
switch err.(type) {
|
||||
case validation.Errors:
|
||||
render.Render(w, r, ErrValidation(err))
|
||||
render.Render(w, r, ErrValidation(ErrProfileValidation, err.(validation.Errors)))
|
||||
return
|
||||
}
|
||||
render.Render(w, r, ErrRender(err))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue