Total Lines | 29 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 0 |
1 | package mollie |
||
2 | |||
3 | import "fmt" |
||
4 | |||
5 | // ErrorLinks container references to common urls |
||
6 | // returned with errors. |
||
7 | type ErrorLinks struct { |
||
8 | Documentation *URL `json:"documentation,omitempty"` |
||
9 | } |
||
10 | |||
11 | // BaseError contains the general error structure |
||
12 | // returned by mollie. |
||
13 | type BaseError struct { |
||
14 | Status int `json:"status,omitempty"` |
||
15 | Title string `json:"title,omitempty"` |
||
16 | Detail string `json:"detail,omitempty"` |
||
17 | Field string `json:"field,omitempty"` |
||
18 | Links *ErrorLinks `json:"_links,omitempty"` |
||
19 | } |
||
20 | |||
21 | // Error interface compliance. |
||
22 | func (be *BaseError) Error() string { |
||
23 | 1 | str := fmt.Sprintf("%d %s: %s", be.Status, be.Title, be.Detail) |
|
24 | |||
25 | 1 | if len(be.Field) > 0 { |
|
26 | 1 | str = fmt.Sprintf("%s, affected field: %s", str, be.Field) |
|
27 | } |
||
28 | |||
29 | 1 | return str |
|
30 | } |
||
31 |