forked from rainhq/signalr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
errors.go
145 lines (111 loc) · 2.45 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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
package signalr
import (
"errors"
"fmt"
)
type NegotiateError struct {
cause error
}
func (e *NegotiateError) Error() string {
return fmt.Sprintf("negotiate failed: %+v", e.cause)
}
func (e *NegotiateError) Unwrap() error {
return e.cause
}
type ConnectError struct {
cause error
}
func (e *ConnectError) Error() string {
return fmt.Sprintf("connect failed: %+v", e.cause)
}
func (e *ConnectError) Unwrap() error {
return e.cause
}
type StartError struct {
cause error
}
func (e *StartError) Error() string {
return fmt.Sprintf("start failed: %+v", e.cause)
}
func (e *StartError) Unwrap() error {
return e.cause
}
type DialError struct {
status int
cause error
}
func (e *DialError) Error() string {
if e.status != 0 {
return fmt.Sprintf("dial failed (%d): %v", e.status, e.cause)
}
return fmt.Sprintf("dial failed: %v", e.cause)
}
func (e *DialError) Unwrap() error {
return e.cause
}
type CloseError struct {
code int
text string
}
func (e *CloseError) Error() string {
if e.text != "" {
return fmt.Sprintf("websocket closed %d: %s", e.code, e.text)
}
return fmt.Sprintf("websocket closed %d", e.code)
}
func IsCloseError(err error, codes ...int) bool {
closeErr := &CloseError{}
if !errors.As(err, &closeErr) {
return false
}
for _, code := range codes {
if closeErr.code == code {
return true
}
}
return false
}
type ReadError struct {
cause error
}
func (e *ReadError) Error() string {
return fmt.Sprintf("read failed: %+v", e.cause)
}
func (e *ReadError) Unwrap() error {
return e.cause
}
type WriteError struct {
cause error
}
func (e *WriteError) Error() string {
return fmt.Sprintf("write failed: %+v", e.cause)
}
func (e *WriteError) Unwrap() error {
return e.cause
}
type InvalidStartResponseError struct {
actual string
}
func (e *InvalidStartResponseError) Error() string {
return fmt.Sprintf("expected start response %q, got %q", "started", e.actual)
}
type InvalidInitMessageError struct {
actual int
}
func (e *InvalidInitMessageError) Error() string {
return fmt.Sprintf("expected init message S value %d, got %d", 1, e.actual)
}
type DuplicateCallbackError struct {
method string
}
func (e *DuplicateCallbackError) Error() string {
return fmt.Sprintf("duplicate callback for method %q", e.method)
}
type InvocationError struct {
method string
id int
message string
}
func (e *InvocationError) Error() string {
return fmt.Sprintf("failed to invoke %q (%d): %s", e.method, e.id, e.message)
}