Aneurin Barker Snook 1 рік тому
батько
коміт
3aeea424be
1 змінених файлів з 5 додано та 8 видалено
  1. 5 8
      error.go

+ 5 - 8
error.go

@@ -37,14 +37,7 @@ type Error struct {
 }
 
 // Error retrieves the message of a REST API error.
-// If it has a "error" string attached using WithData or WithError, that message is returned.
-// Otherwise, the Error's own message is returned.
 func (e Error) Error() string {
-	if e.Data != nil && e.Data["error"] != nil {
-		if value, ok := e.Data["error"].(string); ok {
-			return value
-		}
-	}
 	return e.Message
 }
 
@@ -73,8 +66,12 @@ func (e Error) WithData(data map[string]interface{}) Error {
 	return e
 }
 
-// WithError returns a copy of the HTTP error with the given error's message merged in to its additional data.
+// WithError returns a copy of the HTTP error with the given error added either as the Message, if it empty, or as additional data.
 func (e Error) WithError(err error) Error {
+	if e.Message == "" {
+		return e.WithMessage(err.Error())
+	}
+
 	return e.WithData(map[string]interface{}{
 		"error": err.Error(),
 	})