-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
err.go
28 lines (23 loc) · 855 Bytes
/
err.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
package clearbank
import "fmt"
type UnexpectedResponse struct {
Status int
Body string
}
func (r UnexpectedResponse) Error() string {
return fmt.Sprintf("Unexpected response from API. Status: %d Body: %s", r.Status, r.Body)
}
type ErrResponse struct {
Type string `json:"type"`
Title string `json:"title"`
Status int `json:"status" validate:"required"`
Details string `json:"detail"`
Instance string `json:"instance"`
Errors map[string][]string `json:"errors"`
}
func (e ErrResponse) Error() string {
if len(e.Errors) == 0 {
return fmt.Sprintf("Error during API call. Status: %d Type: %s Title: %s", e.Status, e.Type, e.Title)
}
return fmt.Sprintf("Error during API call. Status: %d Type: %s Title: %s Errors: %s", e.Status, e.Type, e.Title, e.Errors)
}