-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy patherrors.go
63 lines (53 loc) · 1.21 KB
/
errors.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package sarufi
import "fmt"
type NotFoundError struct {
Message string `json:"message"`
Detail string `json:"detail"`
}
func (nf *NotFoundError) Error() string {
if nf != nil {
if nf.Message != "" {
return fmt.Sprintf("status code 404: %s", nf.Message)
} else if nf.Detail != "" {
return fmt.Sprintf("status code 404: %s", nf.Detail)
}
}
return ""
}
type Unauthorized struct {
Message string `json:"message"`
Detail string `json:"detail"`
}
func (ua *Unauthorized) Error() string {
if ua != nil {
if ua.Message != "" {
return fmt.Sprintf("status code 401: %s", ua.Message)
} else if ua.Detail != "" {
return fmt.Sprintf("status code 401: %s", ua.Detail)
}
}
return ""
}
type Detail struct {
Loc []string `json:"loc"`
Message string `json:"msg"`
Type string `json:"type"`
}
type ConflictError struct {
Detail Detail `json:"detail"`
}
func (c *ConflictError) Error() string {
if c != nil {
return fmt.Sprintf("status code 409: %s", c.Detail.Message)
}
return ""
}
type UnprocessableEntity struct {
Detail []Detail `json:"detail"`
}
func (ue *UnprocessableEntity) Error() string {
if ue != nil {
return fmt.Sprintf("status code 422: %s", ue.Detail[0].Message)
}
return ""
}