File tree 3 files changed +43
-0
lines changed 3 files changed +43
-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 exhttp
8
+
9
+ import (
10
+ "errors"
11
+ "net"
12
+ "syscall"
13
+
14
+ "golang.org/x/net/http2"
15
+ )
16
+
17
+ func IsNetworkError (err error ) bool {
18
+ var errno syscall.Errno
19
+ var netError net.Error
20
+
21
+ if errors .As (err , & errno ) {
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
+ } else if errors .As (err , & netError ) {
34
+ return true
35
+ } else if errors .As (err , & http2.StreamError {}) {
36
+ return true
37
+ }
38
+
39
+ return false
40
+ }
Original file line number Diff line number Diff line change @@ -11,6 +11,7 @@ require (
11
11
github.com/rs/zerolog v1.34.0
12
12
github.com/stretchr/testify v1.10.0
13
13
golang.org/x/exp v0.0.0-20250506013437-ce4c2cf36ca6
14
+ golang.org/x/net v0.40.0
14
15
golang.org/x/sys v0.33.0
15
16
golang.org/x/text v0.25.0
16
17
google.golang.org/protobuf v1.36.6
Original file line number Diff line number Diff line change @@ -27,6 +27,8 @@ github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOf
27
27
github.com/stretchr/testify v1.10.0 /go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY =
28
28
golang.org/x/exp v0.0.0-20250506013437-ce4c2cf36ca6 h1:y5zboxd6LQAqYIhHnB48p0ByQ/GnQx2BE33L8BOHQkI =
29
29
golang.org/x/exp v0.0.0-20250506013437-ce4c2cf36ca6 /go.mod h1:U6Lno4MTRCDY+Ba7aCcauB9T60gsv5s4ralQzP72ZoQ =
30
+ golang.org/x/net v0.40.0 h1:79Xs7wF06Gbdcg4kdCCIQArK11Z1hr5POQ6+fIYHNuY =
31
+ golang.org/x/net v0.40.0 /go.mod h1:y0hY0exeL2Pku80/zKK7tpntoX23cqL3Oa6njdgRtds =
30
32
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab /go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg =
31
33
golang.org/x/sys v0.6.0 /go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg =
32
34
golang.org/x/sys v0.12.0 /go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg =
You can’t perform that action at this time.
0 commit comments