Change ValidationError to a pointer

In Prep for adding at leats one more field, make this operate more list
StatusError.
This commit is contained in:
Tim Hockin
2014-11-21 06:11:23 +08:00
parent d4c37e352e
commit b08e5b24b0
7 changed files with 59 additions and 60 deletions

View File

@@ -30,6 +30,8 @@ type StatusError struct {
ErrStatus api.Status
}
var _ error = &statusError{}
// Error implements the Error interface.
func (e *StatusError) Error() string {
return e.ErrStatus.Message
@@ -107,7 +109,7 @@ func NewConflict(kind, name string, err error) error {
func NewInvalid(kind, name string, errs ValidationErrorList) error {
causes := make([]api.StatusCause, 0, len(errs))
for i := range errs {
if err, ok := errs[i].(ValidationError); ok {
if err, ok := errs[i].(*ValidationError); ok {
causes = append(causes, api.StatusCause{
Type: api.CauseType(err.Type),
Message: err.Error(),
@@ -130,18 +132,16 @@ func NewInvalid(kind, name string, errs ValidationErrorList) error {
// NewBadRequest creates an error that indicates that the request is invalid and can not be processed.
func NewBadRequest(reason string) error {
return &StatusError{
api.Status{
Status: api.StatusFailure,
Code: http.StatusBadRequest,
Reason: api.StatusReasonBadRequest,
Details: &api.StatusDetails{
Causes: []api.StatusCause{
{Message: reason},
},
return &StatusError{api.Status{
Status: api.StatusFailure,
Code: http.StatusBadRequest,
Reason: api.StatusReasonBadRequest,
Details: &api.StatusDetails{
Causes: []api.StatusCause{
{Message: reason},
},
},
}
}}
}
// NewInternalError returns an error indicating the item is invalid and cannot be processed.