This repository has been archived by the owner on May 1, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
/
errors.go
195 lines (159 loc) · 4.82 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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
package webwire
import (
"fmt"
)
// ErrBufferOverflow represents a message buffer overflow error
type ErrBufferOverflow struct{}
// Error implements the error interface
func (err ErrBufferOverflow) Error() string {
return "message buffer overflow"
}
// ErrDeadlineExceeded represents a failure due to an excess of a user-defined
// deadline
type ErrDeadlineExceeded struct {
Cause error
}
// Error implements the error interface
func (err ErrDeadlineExceeded) Error() string {
return err.Cause.Error()
}
// ErrDisconnected represents an error indicating a disconnected connection
type ErrDisconnected struct {
Cause error
}
// Error implements the error interface
func (err ErrDisconnected) Error() string {
if err.Cause == nil {
return "disconnected"
}
return err.Cause.Error()
}
// ErrDialTimeout represents a dialing error caused by a timeout
type ErrDialTimeout struct{}
// Error implements the error interface
func (err ErrDialTimeout) Error() string {
return "dial timed out"
}
// ErrIncompatibleProtocolVersion represents a connection error indicating that
// the server requires an incompatible version of the protocol and can't
// therefore be connected to
type ErrIncompatibleProtocolVersion struct {
RequiredVersion string
SupportedVersion string
}
// Error implements the error interface
func (err ErrIncompatibleProtocolVersion) Error() string {
return fmt.Sprintf(
"unsupported protocol version: %s (supported: %s)",
err.RequiredVersion,
err.SupportedVersion,
)
}
// ErrInternal represents a server-side internal error
type ErrInternal struct{}
// Error implements the error interface
func (err ErrInternal) Error() string {
return "internal server error"
}
// ErrMaxSessConnsReached represents an authentication error indicating that the
// given session already reached the maximum number of concurrent connections
type ErrMaxSessConnsReached struct{}
// Error implements the error interface
func (err ErrMaxSessConnsReached) Error() string {
return "reached maximum number of concurrent session connections"
}
// ErrProtocol represents a protocol error
type ErrProtocol struct {
Cause error
}
// ErrNewProtocol constructs a new ErrProtocol error based on the actual error
func ErrNewProtocol(err error) ErrProtocol {
return ErrProtocol{
Cause: err,
}
}
// Error implements the error interface
func (err ErrProtocol) Error() string {
return err.Cause.Error()
}
// ErrRequest represents an error returned when a request couldn't be processed
type ErrRequest struct {
Code string
Message string
}
// Error implements the error interface
func (err ErrRequest) Error() string {
return err.Message
}
// ErrServerShutdown represents a request error indicating that the request
// cannot be processed due to the server currently being shut down
type ErrServerShutdown struct{}
// Error implements the error interface
func (err ErrServerShutdown) Error() string {
return "server is currently being shut down and won't process the request"
}
// ErrSessionNotFound represents a session restoration error indicating that the
// server didn't find the session to be restored
type ErrSessionNotFound struct{}
// Error implements the error interface
func (err ErrSessionNotFound) Error() string {
return "session not found"
}
// ErrSessionsDisabled represents an error indicating that the server has
// sessions disabled
type ErrSessionsDisabled struct{}
// Error implements the error interface
func (err ErrSessionsDisabled) Error() string {
return "sessions are disabled for this server"
}
// ErrTimeout represents a failure caused by a timeout
type ErrTimeout struct {
Cause error
}
// Error implements the error interface
func (err ErrTimeout) Error() string {
return err.Cause.Error()
}
// ErrTransmission represents a connection error indicating a failed
// transmission
type ErrTransmission struct {
Cause error
}
// Error implements the error interface
func (err ErrTransmission) Error() string {
return fmt.Sprintf("message transmission failed: %s", err.Cause)
}
// ErrCanceled represents a failure due to cancellation
type ErrCanceled struct {
Cause error
}
// Error implements the error interface
func (err ErrCanceled) Error() string {
return err.Cause.Error()
}
// IsErrTimeout returns true if the given error is either a ErrTimeout
// or a ErrDeadlineExceeded, otherwise returns false
func IsErrTimeout(err error) bool {
switch err.(type) {
case ErrTimeout:
return true
case ErrDeadlineExceeded:
return true
}
return false
}
// IsErrCanceled returns true if the given error is a ErrCanceled,
// otherwise returns false
func IsErrCanceled(err error) bool {
switch err.(type) {
case ErrCanceled:
return true
}
return false
}
// ErrSockRead defines the interface of a webwire.Socket.Read error
type ErrSockRead interface {
error
// IsCloseErr must return true if the error represents a closure error
IsCloseErr() bool
}