Skip to content

Commit aa35dd1

Browse files
committed
http: cleanup http related errors
We don't need to return information about the actual HTTP error. That's usually not something the user cares about (and is usually implied from the command). This way, we get an actual context canceled error when the context is canceled.
1 parent a9ee130 commit aa35dd1

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)