-
Notifications
You must be signed in to change notification settings - Fork 0
/
error.go
66 lines (50 loc) · 2.06 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package circlesdk
import "fmt"
func (e *Error) Error() string {
return fmt.Sprintf("%d: %s", e.Code, e.Message)
}
// Error details for unsuccessful API requests.
// https://developers.circle.com/docs/common-error-responses
type Error struct {
// General error type.
// https://developers.circle.com/docs/api-response-errors
Code int `json:"code,omitempty"`
// Human-friendly message.
Message string `json:"message,omitempty"`
// Additional error details.
// https://developers.circle.com/docs/entity-errors
Details []ExtendedErrorDetails `json:"errors,omitempty"`
}
// ExtendedErrorDetails contains a list of one or multiple error descriptions
// associated with it.
type ExtendedErrorDetails struct {
// Type of an error
ErrorType string `json:"error,omitempty"`
// Human-friendly message
Message string `json:"message,omitempty"`
// Period-separated path to the property that causes this error.
// For example: address.billingCountry
Location string `json:"location,omitempty"`
// Actual value of the property specified in location key, as
// received by the server.
InvalidValue string `json:"invalidValue,omitempty"`
// Special object that contains additional details about the error
// and could be used for programmatic handling on the client side.
Constraints ErrorConstraints `json:"constraints,omitempty"`
}
// ErrorConstraints contains additional details about the error and could be used
// for programmatic handling on the client side.
type ErrorConstraints struct {
// Used to describe `max_value` or `min_value` errors.
Min string `json:"min,omitempty"`
// Used to describe `max_value` or `min_value` errors.
Max string `json:"max,omitempty"`
// Used to describe `max_value` or `min_value` errors.
Inclusive bool `json:"inclusive,omitempty"`
// Used to describe `pattern_mismatch` errors.
Pattern string `json:"pattern,omitempty"`
// Used to describe `number_format` errors.
MaxIntegralDigits int `json:"max-integral-digits,omitempty"`
// Used to described `number_format` errors.
MaxFractionalDigits int `json:"max-fractional-digits,omitempty"`
}