json-api error format

Part of #11.
This commit is contained in:
Matthew Dillon 2015-10-14 10:28:09 -07:00
parent 2894efaf46
commit 708eed5817
6 changed files with 62 additions and 14 deletions

View file

@ -2,7 +2,23 @@ package types
import "encoding/json"
type ValidationError map[string][]string
type Source struct {
Pointer string `json:"pointer"`
}
type ErrorDetail struct {
Source `json:"source"`
Detail string `json:"detail"`
}
func NewValidationError(attr, message string) ErrorDetail {
return ErrorDetail{
Source: Source{Pointer: "data/attributes/" + attr},
Detail: message,
}
}
type ValidationError []ErrorDetail
func (v ValidationError) Error() string {
errs, err := json.Marshal(struct {