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 {
40 func (e *updateError) Error() string {
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)
48 } else if issues, ok := e.Issues.([]interface{}); ok {
49 for _, v := range issues {
51 messages = append(messages, m)
55 return strings.Join(messages, ", ")
58 // APIError returns the error specified in the API response
59 func (e *updateError) APIError() string {
63 type deleteError struct {
67 func (e *deleteError) Error() string {
71 // AuthenticationError implements the error interface and it's returned
72 // when API responses have authentication errors
73 type AuthenticationError struct {
78 func (e *AuthenticationError) Error() string {
79 return fmt.Sprintf("%d, %s", e.errNo, e.message)