errors.go 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. package cloudflare
  2. // Error messages
  3. const (
  4. errEmptyCredentials = "invalid credentials: key & email must not be empty"
  5. errEmptyAPIToken = "invalid credentials: API Token must not be empty"
  6. errMakeRequestError = "error from makeRequest"
  7. errUnmarshalError = "error unmarshalling the JSON response"
  8. errRequestNotSuccessful = "error reported by API"
  9. errMissingAccountID = "account ID is empty and must be provided"
  10. )
  11. var _ Error = &UserError{}
  12. // Error represents an error returned from this library.
  13. type Error interface {
  14. error
  15. // Raised when user credentials or configuration is invalid.
  16. User() bool
  17. // Raised when a parsing error (e.g. JSON) occurs.
  18. Parse() bool
  19. // Raised when a network error occurs.
  20. Network() bool
  21. // Contains the most recent error.
  22. }
  23. // UserError represents a user-generated error.
  24. type UserError struct {
  25. Err error
  26. }
  27. // User is a user-caused error.
  28. func (e *UserError) User() bool {
  29. return true
  30. }
  31. // Network error.
  32. func (e *UserError) Network() bool {
  33. return false
  34. }
  35. // Parse error.
  36. func (e *UserError) Parse() bool {
  37. return true
  38. }
  39. // Error wraps the underlying error.
  40. func (e *UserError) Error() string {
  41. return e.Err.Error()
  42. }