forked from beeker1121/mailchimp-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patherrors.go
36 lines (30 loc) · 956 Bytes
/
errors.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package mailchimp
import (
"errors"
"fmt"
)
var (
// ErrAPIKeyNotSet is returned when a call to the API is
// attempted before the user set an API key.
ErrAPIKeyNotSet = errors.New("mailchimp: API key has not been set")
// ErrAPIKeyFormat is returned when the provided API key
// is in an invalid format.
ErrAPIKeyFormat = errors.New("mailchimp: Invalid API key format")
)
// Error defines a field error.
type Error struct {
Field string `json:"field"`
Message string `json:"message"`
}
// APIError defines the MailChimp API response error structure.
type APIError struct {
Type string `json:"type"`
Title string `json:"title"`
Status int `json:"status"`
Detail string `json:"detail"`
Errors []Error `json:"errors,omitempty"`
}
// Error satisfies the error interface method.
func (ae *APIError) Error() string {
return fmt.Sprintf("mailchimp: API Error: Status: %d Title: %s Detail: %s", ae.Status, ae.Title, ae.Detail)
}