-
Notifications
You must be signed in to change notification settings - Fork 1
/
error.go
52 lines (47 loc) · 1.55 KB
/
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package sumup
import "fmt"
// APIError is custom error type for SumUp API that combinas *all* of our
// current error types into one underlying struct.
type APIError struct {
// Platform code for the error.
ErrorCode *string `json:"error_code,omitempty"`
// Short description of the error.
Message *string `json:"message,omitempty"`
// Parameter name (with relative location) to which the error applies. Parameters from embedded resources are displayed using dot notation. For example, `card.name` refers to the `name` parameter embedded in the `card` object.
Param *string `json:"param,omitempty"`
// Short description of the error.
ErrorMessage *string `json:"error_message,omitempty"`
// HTTP status code for the error.
StatusCode *string `json:"status_code,omitempty"`
// Details of the error.
Details *string `json:"details,omitempty"`
FailedConstraints *[]string `json:"failed_constraints,omitempty"`
// The status code.
Status *float64 `json:"status,omitempty"`
// Short title of the error.
Title *string `json:"title,omitempty"`
}
// Error returns the error message.
func (e *APIError) Error() string {
var code string
if e.ErrorCode != nil {
code = *e.ErrorCode
}
if e.StatusCode != nil && code == "" {
code = *e.StatusCode
}
if e.Title != nil && code == "" {
code = *e.Title
}
var message string
if e.Message != nil {
message = *e.Message
}
if e.ErrorMessage != nil && message == "" {
message = *e.ErrorMessage
}
if e.Details != nil && message == "" {
message = *e.Details
}
return fmt.Sprintf("%s: %s", code, message)
}