]> git.immae.eu Git - github/fretlink/terraform-provider-statuscake.git/blame - vendor/github.com/DreamItGetIT/statuscake/errors.go
vendor: github.com/hashicorp/terraform/...@v0.10.0
[github/fretlink/terraform-provider-statuscake.git] / vendor / github.com / DreamItGetIT / statuscake / errors.go
CommitLineData
9b12e4fe
JC
1package statuscake
2
3import (
4 "fmt"
5 "strings"
6)
7
8// APIError implements the error interface an it's used when the API response has errors.
9type APIError interface {
10 APIError() string
11}
12
13type httpError struct {
14 status string
15 statusCode int
16}
17
18func (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.
23type ValidationError map[string]string
24
25func (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
36type updateError struct {
37 Issues interface{}
38}
39
40func (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
59func (e *updateError) APIError() string {
60 return e.Error()
61}
62
63type deleteError struct {
64 Message string
65}
66
67func (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
73type AuthenticationError struct {
74 errNo int
75 message string
76}
77
78func (e *AuthenticationError) Error() string {
79 return fmt.Sprintf("%d, %s", e.errNo, e.message)
80}