forked from tj/go-dropbox
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherror.go
More file actions
58 lines (49 loc) · 951 Bytes
/
error.go
File metadata and controls
58 lines (49 loc) · 951 Bytes
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
package dropbox
import (
"fmt"
"net/http"
)
// error tag constant values
const (
TooManyRequests = "too_many_requests"
)
// Error response.
type Error struct {
Status string
StatusCode int
Header http.Header
Summary string `json:"error_summary"`
Message string `json:"user_message"` // optionally present
Err interface{} `json:"error"`
}
// Error string.
func (e *Error) Error() string {
if e.Summary != "" {
return e.Summary
}
return fmt.Sprintf("%d: %s", e.StatusCode, e.Status)
}
// Tag returns the inner tag for the error
func (e *Error) Tag() (tag, value string) {
payload, ok := e.Err.(map[string]interface{})
if !ok {
val, ok := e.Err.(string)
if ok {
return "", val
}
return
}
tag, ok = payload[".tag"].(string)
if !ok {
return
}
data, ok := payload[tag].(map[string]interface{})
if !ok {
return
}
value, ok = data[".tag"].(string)
if !ok {
return
}
return
}