-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathis_net_error.go
30 lines (27 loc) · 1.12 KB
/
is_net_error.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
package util
import (
"errors"
"net"
"strings"
"syscall"
)
func IsNetError(err error) bool {
if err == nil {
return false
} else if _, ok := err.(*net.OpError); ok {
return true
}
return errors.Is(err, syscall.ECONNRESET) || // connection reset by peer
errors.Is(err, syscall.EPIPE) || // broken pipe
errors.Is(err, syscall.EHOSTUNREACH) || // no route to host
errors.Is(err, syscall.ENETUNREACH) || // network is unreachable
errors.Is(err, syscall.ENETDOWN) || // network is down
errors.Is(err, syscall.ECONNREFUSED) || // connection refused
errors.Is(err, syscall.ETIMEDOUT) || // connection timed out
strings.HasSuffix(err.Error(), "; CANCEL") || // http2.ErrCodeCancel
strings.HasSuffix(err.Error(), "; PROTOCOL_ERROR") || // http2.ErrCodeProtocol
strings.HasSuffix(err.Error(), "http2: stream closed") || // http2.ErrCodeStreamClosed
strings.HasSuffix(err.Error(), "http2: request body closed due to handler exiting") || // http2.errHandlerComplete
strings.HasSuffix(err.Error(), "client disconnected") || // http.http2errClientDisconnected
strings.HasSuffix(err.Error(), "H3_REQUEST_CANCELLED")
}