-
Notifications
You must be signed in to change notification settings - Fork 47
/
http.go
36 lines (32 loc) · 959 Bytes
/
http.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 api
import (
"fmt"
"net/url"
"strings"
)
// HTTPError represents an error response from the GitHub API.
type HTTPError struct {
AcceptedOAuthScopes string
Errors []HTTPErrorItem
Message string
OAuthScopes string
RequestURL *url.URL
StatusCode int
}
// HTTPErrorItem stores additional information about an error response
// returned from the GitHub API.
type HTTPErrorItem struct {
Message string
Resource string
Field string
Code string
}
// Allow HTTPError to satisfy error interface.
func (err HTTPError) Error() string {
if msgs := strings.SplitN(err.Message, "\n", 2); len(msgs) > 1 {
return fmt.Sprintf("HTTP %d: %s (%s)\n%s", err.StatusCode, msgs[0], err.RequestURL, msgs[1])
} else if err.Message != "" {
return fmt.Sprintf("HTTP %d: %s (%s)", err.StatusCode, err.Message, err.RequestURL)
}
return fmt.Sprintf("HTTP %d (%s)", err.StatusCode, err.RequestURL)
}