/
error.go
48 lines (40 loc) · 886 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
45
46
47
48
package github
import (
"fmt"
"github.com/ovh/cds/sdk"
)
//Error wraps github error format
type ghError struct {
ID string `json:"error"`
Desc string `json:"error_description"`
URI string `json:"error_uri"`
}
func (e ghError) Error() string {
return fmt.Sprintf("(gh_%s) %s", e.ID, e.Desc)
}
func (e ghError) String() string {
return e.Error()
}
//Github errors
var (
ErrorRateLimit = &ghError{
ID: "rate_limit",
Desc: "Rate Limit reached",
URI: "https://developer.github.com/v3/#rate-limiting",
}
ErrorUnauthorized = &ghError{
ID: "bad_credentials",
Desc: "Bad credentials",
URI: "https://developer.github.com/v3",
}
)
//errorAPI creates a new error
func errorAPI(body []byte) error {
res := map[string]string{}
sdk.JSONUnmarshal(body, &res)
return ghError{
ID: "api_error",
Desc: res["message"],
URI: res["documentation_url"],
}
}