Skip to content

Commit ba86293

Browse files
authored
Merge pull request #173 from ipfs/fix/nice-errors
http: cleanup http related errors
2 parents a9ee130 + aa35dd1 commit ba86293

File tree

1 file changed

+8
-15
lines changed

1 file changed

+8
-15
lines changed

http/client.go

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,14 @@ func (c *client) Execute(req *cmds.Request, re cmds.ResponseEmitter, env cmds.En
8888

8989
res, err := c.send(req)
9090
if err != nil {
91-
if isConnRefused(err) {
91+
// Unwrap any URL errors. We don't really need to expose the
92+
// underlying HTTP nonsense to the user.
93+
if urlerr, ok := err.(*url.Error); ok {
94+
err = urlerr.Err
95+
}
96+
97+
if netoperr, ok := err.(*net.OpError); ok && netoperr.Op == "dial" {
98+
// Connection refused.
9299
if c.fallback != nil {
93100
// XXX: this runs the PreRun twice
94101
return c.fallback.Execute(req, re, env)
@@ -237,17 +244,3 @@ func getQuery(req *cmds.Request) (string, error) {
237244

238245
return query.Encode(), nil
239246
}
240-
241-
func isConnRefused(err error) bool {
242-
// unwrap url errors from http calls
243-
if urlerr, ok := err.(*url.Error); ok {
244-
err = urlerr.Err
245-
}
246-
247-
netoperr, ok := err.(*net.OpError)
248-
if !ok {
249-
return false
250-
}
251-
252-
return netoperr.Op == "dial"
253-
}

0 commit comments

Comments
 (0)