From 9b12e4fe6f3c95986f1f3ec791636c58ca7e7583 Mon Sep 17 00:00:00 2001 From: Jake Champlin Date: Fri, 9 Jun 2017 17:54:32 +0000 Subject: Transfer of provider code --- .../github.com/DreamItGetIT/statuscake/errors.go | 80 ++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 vendor/github.com/DreamItGetIT/statuscake/errors.go (limited to 'vendor/github.com/DreamItGetIT/statuscake/errors.go') 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 @@ +package statuscake + +import ( + "fmt" + "strings" +) + +// APIError implements the error interface an it's used when the API response has errors. +type APIError interface { + APIError() string +} + +type httpError struct { + status string + statusCode int +} + +func (e *httpError) Error() string { + return fmt.Sprintf("HTTP error: %d - %s", e.statusCode, e.status) +} + +// ValidationError is a map where the key is the invalid field and the value is a message describing why the field is invalid. +type ValidationError map[string]string + +func (e ValidationError) Error() string { + var messages []string + + for k, v := range e { + m := fmt.Sprintf("%s %s", k, v) + messages = append(messages, m) + } + + return strings.Join(messages, ", ") +} + +type updateError struct { + Issues interface{} +} + +func (e *updateError) Error() string { + var messages []string + + if issues, ok := e.Issues.(map[string]interface{}); ok { + for k, v := range issues { + m := fmt.Sprintf("%s %s", k, v) + messages = append(messages, m) + } + } else if issues, ok := e.Issues.([]interface{}); ok { + for _, v := range issues { + m := fmt.Sprint(v) + messages = append(messages, m) + } + } + + return strings.Join(messages, ", ") +} + +// APIError returns the error specified in the API response +func (e *updateError) APIError() string { + return e.Error() +} + +type deleteError struct { + Message string +} + +func (e *deleteError) Error() string { + return e.Message +} + +// AuthenticationError implements the error interface and it's returned +// when API responses have authentication errors +type AuthenticationError struct { + errNo int + message string +} + +func (e *AuthenticationError) Error() string { + return fmt.Sprintf("%d, %s", e.errNo, e.message) +} -- cgit v1.2.3