-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherrors.go
More file actions
45 lines (40 loc) · 1.01 KB
/
errors.go
File metadata and controls
45 lines (40 loc) · 1.01 KB
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
package zsocket
import "errors"
var (
ErrBadHandshake = errors.New("zsocket: bad handshake")
ErrCloseSent = errors.New("zsocket: close sent")
ErrReadLimit = errors.New("zsocket: read limit exceeded")
)
// IsCloseError checks whether err is a CloseError with one of the given codes.
func IsCloseError(err error, codes ...CloseCode) bool {
var ce CloseError
if !errors.As(err, &ce) {
return false
}
if len(codes) == 0 {
return true
}
for _, code := range codes {
if ce.Code == code {
return true
}
}
return false
}
// IsUnexpectedCloseError reports whether err is a CloseError that is not expected.
func IsUnexpectedCloseError(err error, expectedCodes ...CloseCode) bool {
var ce CloseError
if !errors.As(err, &ce) {
return false
}
for _, code := range expectedCodes {
if ce.Code == code {
return false
}
}
return true
}
// FormatCloseMessage formats close payload bytes from code and text.
func FormatCloseMessage(code CloseCode, text string) []byte {
return closePayload(code, text)
}