forked from hyperworks/go-getstream
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patherror.go
42 lines (33 loc) · 804 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
package getstream
import (
"time"
)
/*{"code": 5, "detail": "Please use signedto instead of signedTo for your field name", "
duration": "36ms", "exception": "CustomFieldException", "status_code": 400} */
type Error struct {
Code int
StatusCode int `json:"status_code"`
Detail string
RawDuration string `json:"duration"`
Exception string
}
var _ error = &Error{}
func (err *Error) Duration() time.Duration {
result, e := time.ParseDuration(err.RawDuration)
if e != nil {
return time.Duration(0)
}
return result
}
func (err *Error) Error() string {
str := err.Exception
if err.RawDuration != "" {
if duration := err.Duration(); duration > 0 {
str += " (" + duration.String() + ")"
}
}
if err.Detail != "" {
str += ": " + err.Detail
}
return str
}