/
errors.go
40 lines (34 loc) · 1.17 KB
/
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
37
38
39
40
package aftership
import (
"encoding/json"
)
// Error messages
const (
errEmptyAPIKey = "invalid credentials: API Key must not be empty"
errMissingTrackingNumber = "tracking number is empty and must be provided"
errMissingTrackingID = "tracking id is empty and must be provided"
errMissingSlugOrTrackingNumber = "slug or tracking number is empty, both of them must be provided"
errExceedRateLimt = "rate limit is exceeded, please wait util %s"
)
// APIError is the error in AfterShip API calls
type APIError struct {
Code int `json:"code"`
Type string `json:"type"`
Message string `json:"message"`
Path string `json:"path"`
}
// Error serializes the error object to JSON and returns it as a string.
func (e *APIError) Error() string {
ret, _ := json.Marshal(e)
return string(ret)
}
// TooManyRequestsError is the too many requests error in AfterShip API calls
type TooManyRequestsError struct {
APIError
RateLimit *RateLimit `json:"rate_limit"`
}
// Error serializes the error object to JSON and returns it as a string.
func (e *TooManyRequestsError) Error() string {
ret, _ := json.Marshal(e)
return string(ret)
}