-
Notifications
You must be signed in to change notification settings - Fork 1
/
error.go
36 lines (29 loc) · 887 Bytes
/
error.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
29
30
31
32
33
34
35
36
package gocardless
import (
"fmt"
"net/url"
)
type Error struct {
Message string `json:"message,omitempty"`
HTTPStatusCode int `json:"code,omitempty"`
Errors map[string][]interface{} `json:"errors,omitempty"`
URL *url.URL `json:"url,omitempty"`
}
func (r *Error) Error() string {
return fmt.Sprintf("%d %s: %v %+v",
r.HTTPStatusCode, r.Message, r.URL, r.Errors)
}
func (r *Error) GetErrorCode() string {
return fmt.Sprintf("%d", r.HTTPStatusCode)
}
func (r *Error) GetErrorMessage() string {
return fmt.Sprintf("%s", r.Message)
}
// prints the struct in a default format with the fields name
func (r *Error) GetErrors() string {
return fmt.Sprintf("%+v", r.Errors)
}
// prints the error URL in the default format
func (r *Error) GetErrorURL() string {
return fmt.Sprintf("%v", r.URL)
}