-
Notifications
You must be signed in to change notification settings - Fork 47
/
errors.go
99 lines (93 loc) · 1.87 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package guac
import (
"fmt"
"strings"
)
type ErrGuac struct {
error
Status Status
Kind ErrKind
}
type ErrKind int
const (
ErrClientBadType ErrKind = iota
ErrClient
ErrClientOverrun
ErrClientTimeout
ErrClientTooMany
ErrConnectionClosed
ErrOther
ErrResourceClosed
ErrResourceConflict
ErrResourceNotFound
ErrSecurity
ErrServerBusy
ErrServer
ErrSessionClosed
ErrSessionConflict
ErrSessionTimeout
ErrUnauthorized
ErrUnsupported
ErrUpstream
ErrUpstreamNotFound
ErrUpstreamTimeout
ErrUpstreamUnavailable
)
// Status convert ErrKind to Status
func (e ErrKind) Status() (state Status) {
switch e {
case ErrClientBadType:
return ClientBadType
case ErrClient:
return ClientBadRequest
case ErrClientOverrun:
return ClientOverrun
case ErrClientTimeout:
return ClientTimeout
case ErrClientTooMany:
return ClientTooMany
case ErrConnectionClosed:
return ServerError
case ErrOther:
return ServerError
case ErrResourceClosed:
return ResourceClosed
case ErrResourceConflict:
return ResourceConflict
case ErrResourceNotFound:
return ResourceNotFound
case ErrSecurity:
return ClientForbidden
case ErrServerBusy:
return ServerBusy
case ErrServer:
return ServerError
case ErrSessionClosed:
return SessionClosed
case ErrSessionConflict:
return SessionConflict
case ErrSessionTimeout:
return SessionTimeout
case ErrUnauthorized:
return ClientUnauthorized
case ErrUnsupported:
return Unsupported
case ErrUpstream:
return UpstreamError
case ErrUpstreamNotFound:
return UpstreamNotFound
case ErrUpstreamTimeout:
return UpstreamTimeout
case ErrUpstreamUnavailable:
return UpstreamUnavailable
}
return
}
// NewError creates a new error struct instance with Kind and included message
func (e ErrKind) NewError(args ...string) error {
return &ErrGuac{
error: fmt.Errorf("%v", strings.Join(args, ", ")),
Status: e.Status(),
Kind: e,
}
}