forked from g8rswimmer/go-twitter
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherror_obj.go
More file actions
61 lines (51 loc) · 1.62 KB
/
error_obj.go
File metadata and controls
61 lines (51 loc) · 1.62 KB
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
49
50
51
52
53
54
55
56
57
58
59
60
61
package twitter
import "fmt"
// ResponseDecodeError is an error when a response has a decoding error, JSON.
type ResponseDecodeError struct {
Name string
Err error
RateLimit *RateLimit
}
func (r *ResponseDecodeError) Error() string {
return fmt.Sprintf("%s decode error: %v", r.Name, r.Err)
}
// Unwrap will return the wrapped error
func (r *ResponseDecodeError) Unwrap() error {
return r.Err
}
// HTTPError is a response error where the body is not JSON, but XML. This commonly seen in 404 errors.
type HTTPError struct {
Status string
StatusCode int
URL string
RateLimit *RateLimit
}
func (h HTTPError) Error() string {
return fmt.Sprintf("twitter [%s] status: %s code: %d", h.URL, h.Status, h.StatusCode)
}
// ErrorObj is part of the partial errors in the response
type ErrorObj struct {
Title string `json:"title"`
Detail string `json:"detail"`
Type string `json:"type"`
ResourceType string `json:"resource_type"`
Parameter string `json:"parameter"`
Value interface{} `json:"value"`
}
// Error is part of the HTTP response error
type Error struct {
Parameters interface{} `json:"parameters"`
Message string `json:"message"`
}
// ErrorResponse is returned by a non-success callout
type ErrorResponse struct {
StatusCode int
Errors []Error `json:"errors"`
Title string `json:"title"`
Detail string `json:"detail"`
Type string `json:"type"`
RateLimit *RateLimit `json:"-"`
}
func (e ErrorResponse) Error() string {
return fmt.Sprintf("twitter callout status %d %s:%s", e.StatusCode, e.Title, e.Detail)
}