From 0058f3076f7e76a280b3b4dbfc30aa64aeb00486 Mon Sep 17 00:00:00 2001 From: toniastro Date: Thu, 19 May 2022 15:03:23 +0100 Subject: [PATCH] Convert error to interface --- error.go | 27 +++++---------------------- 1 file changed, 5 insertions(+), 22 deletions(-) diff --git a/error.go b/error.go index 9bff6d8..bbf97ae 100644 --- a/error.go +++ b/error.go @@ -1,37 +1,20 @@ package juice import ( + "fmt" "strings" ) func (e Error) Error() string { errorBuilder := strings.Builder{} errorBuilder.WriteString(e.Message + " ") - if e.Errors.Amount != nil { - errorBuilder.WriteString("(amount), " + e.Errors.Amount[0] + "; ") - } - if e.Errors.Domain != nil { - errorBuilder.WriteString("(domain), " + e.Errors.Domain[0] + "; ") - } - if e.Errors.Message != "" { - errorBuilder.WriteString(e.Errors.Message + "; ") - } - if e.Errors.PhoneNumber != nil { - errorBuilder.WriteString("(phone number), " + e.Errors.PhoneNumber[0] + "; ") - } - if e.Errors.JuiceUserId != nil { - errorBuilder.WriteString("(juice user id), " + e.Errors.JuiceUserId[0] + " ") + if e.Errors != nil { + errorBuilder.WriteString(fmt.Sprintf("%v", e.Errors) + "; ") } return strings.ToLower(strings.Trim(errorBuilder.String(), ";. ")) } type Error struct { - Errors struct { - Message string `json:"message"` - Amount []string `json:"amount"` - Domain []string `json:"domain"` - PhoneNumber []string `json:"phone_number"` - JuiceUserId []string `json:"juice_user_id"` - } `json:"errors"` - Message string `json:"message"` + Errors interface{} `json:"errors"` + Message string `json:"message"` }