From 5a0f5fe281e2c44475cdae6347210e92bf1dbc89 Mon Sep 17 00:00:00 2001 From: Oliver Hookins Date: Thu, 19 Apr 2018 07:23:28 +0200 Subject: [PATCH] Capture validation errors. --- errors.go | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/errors.go b/errors.go index f74beed..6f3b48d 100644 --- a/errors.go +++ b/errors.go @@ -1,6 +1,10 @@ package contentful -import "net/http" +import ( + "bytes" + "fmt" + "net/http" +) // ErrorResponse model type ErrorResponse struct { @@ -59,15 +63,16 @@ type ValidationFailedError struct { } func (e ValidationFailedError) Error() string { - msg := "" + msg := bytes.Buffer{} + for _, err := range e.APIError.err.Details.Errors { if err.Name == "uniqueFieldIds" || err.Name == "uniqueFieldApiNames" { - return msg - // msg += err.Value["id"].(string) + " should be unique for " + err.Value["name"].(string) + "\n" + return msg.String() } + msg.WriteString(fmt.Sprintf("%s\n", err.Details)) } - return msg + return msg.String() } // NotFoundError for 404 errors