/
knownerrors.go
86 lines (66 loc) · 1.33 KB
/
knownerrors.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
package common
import (
"net"
"strings"
)
var (
suppressErrors = []string{
"http2",
"wsasend",
"tls: unknown certificate",
"tls handshake error",
"use of closed network connection",
}
)
func IsErrExit(err error) bool {
if err == nil {
return false
}
_, ok := err.(*ErrExit)
return ok
}
func IsErrTimeout(err error) bool {
type withTimeout interface {
Timeout() bool
}
if err == nil {
return false
}
errTimeout, ok := err.(withTimeout)
return ok && errTimeout.Timeout()
}
func IsErrNetOperation(err error) bool {
if err == nil {
return false
}
_, ok := err.(*net.OpError)
return ok
}
func IsErrNetClosed(err error) bool {
if err == nil {
return false
}
return strings.Contains(strings.ToLower(err.Error()), "use of closed network connection") ||
strings.Contains(strings.ToLower(err.Error()), " connection was forcibly closed")
}
func IsErrUnexpectedEOF(err error) bool {
if err == nil {
return false
}
return strings.Index(strings.ToLower(err.Error()), "unexpected eof") != -1
}
func IsSuppressedError(err error) bool {
if err == nil {
return false
}
return IsSuppressedErrorMessage(err.Error())
}
func IsSuppressedErrorMessage(err string) bool {
msg := strings.ToLower(err)
for _, se := range suppressErrors {
if strings.Contains(msg, se) {
return true
}
}
return false
}