use json.Marshal provided with validation

This commit is contained in:
dhax 2019-01-08 23:07:17 +01:00
parent cd7d44fcd8
commit 2d7f6be830
5 changed files with 40 additions and 56 deletions

View file

@ -2,6 +2,7 @@ package app
import (
"context"
"errors"
"net/http"
"strconv"
"strings"
@ -14,6 +15,11 @@ import (
"github.com/dhax/go-base/auth/pwdless"
)
// The list of error types returned from account resource.
var (
ErrAccountValidation = errors.New("account validation error")
)
// AccountStore defines database operations for account.
type AccountStore interface {
Get(id int) (*pwdless.Account, error)
@ -103,7 +109,7 @@ func (rs *AccountResource) update(w http.ResponseWriter, r *http.Request) {
if err := rs.Store.Update(acc); err != nil {
switch err.(type) {
case validation.Errors:
render.Render(w, r, ErrValidation(err))
render.Render(w, r, ErrValidation(ErrAccountValidation, err.(validation.Errors)))
return
}
render.Render(w, r, ErrRender(err))