-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patherror.go
48 lines (39 loc) · 864 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 gorso
import (
"encoding/json"
"fmt"
)
type Error struct {
StatusCode int `json:"-"`
Type string `json:"error"`
Description string `json:"error_description"`
}
func NewError(code int, body []byte) *Error {
data := Error{}
if err := json.Unmarshal(body, &data); err != nil {
return &Error{
StatusCode: -1,
Type: "UNKNOWN",
Description: string(body),
}
}
data.StatusCode = code
return &data
}
func (e *Error) Error() string {
return fmt.Sprintf("[goRSO Error]: (%d %s) %s\n", e.StatusCode, e.Type, e.Description)
}
func NewErrorCustom(errType string, desc string) *Error {
return &Error{
StatusCode: -1,
Type: errType,
Description: desc,
}
}
func NewErrorSystem(errType string, err error) *Error {
return &Error{
StatusCode: -1,
Type: errType,
Description: err.Error(),
}
}