diff options
author | Jake Champlin <jake@gnu.space> | 2017-06-09 17:54:32 +0000 |
---|---|---|
committer | Jake Champlin <jake@gnu.space> | 2017-06-09 17:54:32 +0000 |
commit | 9b12e4fe6f3c95986f1f3ec791636c58ca7e7583 (patch) | |
tree | 38f5f12bec0e488a12f0459a7356e6b7de7d8f84 /vendor/github.com/DreamItGetIT/statuscake/errors.go | |
parent | cec3de8a3bcaffd21dedd1bf42da4b490cae7e16 (diff) | |
download | terraform-provider-statuscake-9b12e4fe6f3c95986f1f3ec791636c58ca7e7583.tar.gz terraform-provider-statuscake-9b12e4fe6f3c95986f1f3ec791636c58ca7e7583.tar.zst terraform-provider-statuscake-9b12e4fe6f3c95986f1f3ec791636c58ca7e7583.zip |
Transfer of provider code
Diffstat (limited to 'vendor/github.com/DreamItGetIT/statuscake/errors.go')
-rw-r--r-- | vendor/github.com/DreamItGetIT/statuscake/errors.go | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/vendor/github.com/DreamItGetIT/statuscake/errors.go b/vendor/github.com/DreamItGetIT/statuscake/errors.go new file mode 100644 index 0000000..4c51991 --- /dev/null +++ b/vendor/github.com/DreamItGetIT/statuscake/errors.go | |||
@@ -0,0 +1,80 @@ | |||
1 | package statuscake | ||
2 | |||
3 | import ( | ||
4 | "fmt" | ||
5 | "strings" | ||
6 | ) | ||
7 | |||
8 | // APIError implements the error interface an it's used when the API response has errors. | ||
9 | type APIError interface { | ||
10 | APIError() string | ||
11 | } | ||
12 | |||
13 | type httpError struct { | ||
14 | status string | ||
15 | statusCode int | ||
16 | } | ||
17 | |||
18 | func (e *httpError) Error() string { | ||
19 | return fmt.Sprintf("HTTP error: %d - %s", e.statusCode, e.status) | ||
20 | } | ||
21 | |||
22 | // ValidationError is a map where the key is the invalid field and the value is a message describing why the field is invalid. | ||
23 | type ValidationError map[string]string | ||
24 | |||
25 | func (e ValidationError) Error() string { | ||
26 | var messages []string | ||
27 | |||
28 | for k, v := range e { | ||
29 | m := fmt.Sprintf("%s %s", k, v) | ||
30 | messages = append(messages, m) | ||
31 | } | ||
32 | |||
33 | return strings.Join(messages, ", ") | ||
34 | } | ||
35 | |||
36 | type updateError struct { | ||
37 | Issues interface{} | ||
38 | } | ||
39 | |||
40 | func (e *updateError) Error() string { | ||
41 | var messages []string | ||
42 | |||
43 | if issues, ok := e.Issues.(map[string]interface{}); ok { | ||
44 | for k, v := range issues { | ||
45 | m := fmt.Sprintf("%s %s", k, v) | ||
46 | messages = append(messages, m) | ||
47 | } | ||
48 | } else if issues, ok := e.Issues.([]interface{}); ok { | ||
49 | for _, v := range issues { | ||
50 | m := fmt.Sprint(v) | ||
51 | messages = append(messages, m) | ||
52 | } | ||
53 | } | ||
54 | |||
55 | return strings.Join(messages, ", ") | ||
56 | } | ||
57 | |||
58 | // APIError returns the error specified in the API response | ||
59 | func (e *updateError) APIError() string { | ||
60 | return e.Error() | ||
61 | } | ||
62 | |||
63 | type deleteError struct { | ||
64 | Message string | ||
65 | } | ||
66 | |||
67 | func (e *deleteError) Error() string { | ||
68 | return e.Message | ||
69 | } | ||
70 | |||
71 | // AuthenticationError implements the error interface and it's returned | ||
72 | // when API responses have authentication errors | ||
73 | type AuthenticationError struct { | ||
74 | errNo int | ||
75 | message string | ||
76 | } | ||
77 | |||
78 | func (e *AuthenticationError) Error() string { | ||
79 | return fmt.Sprintf("%d, %s", e.errNo, e.message) | ||
80 | } | ||