-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy patherrors.go
41 lines (34 loc) · 984 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
37
38
39
40
41
package daily
import "fmt"
var (
// HTTP Errors.
ErrBadRequest = "bad request"
ErrUnauthorized = "unauthorized"
ErrTooManyRequests = "too many requests"
ErrInternal = "internal error"
ErrUnexpected = "unexpected error"
// Other errors.
ErrParseError = "json parse error"
)
// Error represents error information related to an API call.
type Error struct {
Message string
StatusCode int
Details *ErrorDetails
RawDetails string
}
func (e Error) Error() string {
if e.Details != nil {
return fmt.Sprintf("daily: %s (status: %d, %s)", e.Message, e.StatusCode, e.Details)
} else {
return fmt.Sprintf("daily: %s (status: %d, details: %s)", e.Message, e.StatusCode, e.RawDetails)
}
}
// ErrorDetails is the daily API error response.
type ErrorDetails struct {
ErrorCode string `json:"error"`
ErrorInfo string `json:"info"`
}
func (ed ErrorDetails) String() string {
return fmt.Sprintf("code: %s, info: %s", ed.ErrorCode, ed.ErrorInfo)
}