Skip to content

Commit

Permalink
Merge pull request #1 from bushaHQ/interface-error
Browse files Browse the repository at this point in the history
Convert error to interface
  • Loading branch information
kayslay authored May 19, 2022
2 parents d2ab928 + 0058f30 commit bfc8eae
Showing 1 changed file with 5 additions and 22 deletions.
27 changes: 5 additions & 22 deletions error.go
Original file line number Diff line number Diff line change
@@ -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"`
}

0 comments on commit bfc8eae

Please sign in to comment.