mirror of
https://github.com/foomo/contentful.git
synced 2026-12-03 20:01:38 +00:00
Merge pull request #23 from ohookins/capture_validation_errors
Capture validation errors.
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user