8 // APIError implements the error interface an it's used when the API response has errors.
9 type APIError interface {
13 type httpError struct {
18 func (e *httpError) Error() string {
19 return fmt.Sprintf("HTTP error: %d - %s", e.statusCode, e.status)
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
25 func (e ValidationError) Error() string {
29 m := fmt.Sprintf("%s %s", k, v)
30 messages = append(messages, m)
33 return strings.Join(messages, ", ")
36 type updateError struct {
41 func (e *updateError) Error() string {
44 messages = append(messages, e.Message)
46 if issues, ok := e.Issues.(map[string]interface{}); ok {
47 for k, v := range issues {
48 m := fmt.Sprintf("%s %s", k, v)
49 messages = append(messages, m)
51 } else if issues, ok := e.Issues.([]interface{}); ok {
52 for _, v := range issues {
54 messages = append(messages, m)
56 } else if issue, ok := e.Issues.(interface{}); ok {
57 m := fmt.Sprint(issue)
58 messages = append(messages, m)
61 return strings.Join(messages, ", ")
64 // APIError returns the error specified in the API response
65 func (e *updateError) APIError() string {
69 type deleteError struct {
73 func (e *deleteError) Error() string {
77 // AuthenticationError implements the error interface and it's returned
78 // when API responses have authentication errors
79 type AuthenticationError struct {
84 func (e *AuthenticationError) Error() string {
85 return fmt.Sprintf("%d, %s", e.errNo, e.message)