File tree Expand file tree Collapse file tree 2 files changed +18
-11
lines changed Expand file tree Collapse file tree 2 files changed +18
-11
lines changed Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ package ghttp
2
2
3
3
import (
4
4
"encoding/json"
5
+ "errors"
5
6
"fmt"
6
7
"github.com/guonaihong/flag"
7
8
"github.com/guonaihong/gurl/core"
@@ -12,9 +13,7 @@ import (
12
13
"github.com/guonaihong/gurl/utils"
13
14
"io"
14
15
_ "io/ioutil"
15
- "net"
16
16
"net/http"
17
- "net/url"
18
17
"os"
19
18
"runtime"
20
19
"strings"
@@ -172,15 +171,9 @@ func CmdErr(err error) {
172
171
return
173
172
}
174
173
175
- if uerr , ok := err .(* url.Error ); ok {
176
- if noerr , ok := uerr .Err .(* net.OpError ); ok {
177
- if scerr , ok := noerr .Err .(* os.SyscallError ); ok {
178
- if scerr .Err == syscall .ECONNREFUSED {
179
- fmt .Printf ("gurl: (7) couldn't connect to host\n " )
180
- os .Exit (7 )
181
- }
182
- }
183
- }
174
+ if errors .Is (err , syscall .ECONNREFUSED ) {
175
+ fmt .Printf ("gurl: (7) couldn't connect to host\n " )
176
+ return
184
177
}
185
178
186
179
fmt .Printf ("%s\n " , err )
Original file line number Diff line number Diff line change
1
+ package ghttp
2
+
3
+ import (
4
+ "errors"
5
+ "github.com/stretchr/testify/assert"
6
+ "net/http"
7
+ "syscall"
8
+ "testing"
9
+ )
10
+
11
+ func Test_Ghttp_CmdErr (t * testing.T ) {
12
+ _ , err := http .Get ("http://127.0.0.1:3333" )
13
+ assert .True (t , errors .Is (err , syscall .ECONNREFUSED ))
14
+ }
You can’t perform that action at this time.
0 commit comments