forked from milosgajdos/go-playht
-
Notifications
You must be signed in to change notification settings - Fork 0
/
error.go
44 lines (38 loc) · 996 Bytes
/
error.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
42
43
44
package playht
import (
"encoding/json"
"errors"
)
var (
// ErrTooManyRequests is returned when the cient hits rate limit.
ErrTooManyRequests = errors.New("too many requests")
// ErrUnexpectedStatusCode is returned when an unexpected status is returned from the API.
ErrUnexpectedStatusCode = errors.New("unexpected status code")
)
// APIErrGen is a generic API error.
type APIErrGen struct {
ID string `json:"error_id"`
Message string `json:"error_message"`
}
// Error implements error interface.
func (e APIErrGen) Error() string {
b, err := json.Marshal(e)
if err != nil {
return "unknown error"
}
return string(b)
}
// APIErrInternal is an error returned
// when the API responds with 50x status code.
type APIErrInternal struct {
Message string `json:"message"`
Err string `json:"error"`
}
// Error implements error interface.
func (e APIErrInternal) Error() string {
b, err := json.Marshal(e)
if err != nil {
return "unknown error"
}
return string(b)
}