File tree 1 file changed +39
-0
lines changed 1 file changed +39
-0
lines changed Original file line number Diff line number Diff line change
1
+ // Copyright (c) 2025 Tulir Asokan
2
+ //
3
+ // This Source Code Form is subject to the terms of the Mozilla Public
4
+ // License, v. 2.0. If a copy of the MPL was not distributed with this
5
+ // file, You can obtain one at http://mozilla.org/MPL/2.0/.
6
+
7
+ package exerrors
8
+
9
+ import (
10
+ "errors"
11
+ "net"
12
+ "syscall"
13
+ )
14
+
15
+ func IsNetworkError (err error ) bool {
16
+ for err != nil {
17
+ if _ , ok := err .(net.Error ); ok {
18
+ return true
19
+ } else if _ , ok := err .(* net.OpError ); ok {
20
+ return true
21
+ } else if errno , ok := err .(syscall.Errno ); ok {
22
+ // common errnos for network related operations
23
+ return errno == syscall .ENETDOWN ||
24
+ errno == syscall .ENETUNREACH ||
25
+ errno == syscall .ENETRESET ||
26
+ errno == syscall .ECONNABORTED ||
27
+ errno == syscall .ECONNRESET ||
28
+ errno == syscall .ENOBUFS ||
29
+ errno == syscall .ETIMEDOUT ||
30
+ errno == syscall .ECONNREFUSED ||
31
+ errno == syscall .EHOSTDOWN ||
32
+ errno == syscall .EHOSTUNREACH
33
+ }
34
+
35
+ err = errors .Unwrap (err )
36
+ }
37
+
38
+ return false
39
+ }
You can’t perform that action at this time.
0 commit comments