Skip to content

Commit

Permalink
http: cleanup http related errors
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Stebalien committed Aug 22, 2019
1 parent a9ee130 commit aa35dd1
Showing 1 changed file with 8 additions and 15 deletions.
23 changes: 8 additions & 15 deletions http/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,14 @@ func (c *client) Execute(req *cmds.Request, re cmds.ResponseEmitter, env cmds.En

res, err := c.send(req)
if err != nil {
if isConnRefused(err) {
// Unwrap any URL errors. We don't really need to expose the
// underlying HTTP nonsense to the user.
if urlerr, ok := err.(*url.Error); ok {
err = urlerr.Err
}

if netoperr, ok := err.(*net.OpError); ok && netoperr.Op == "dial" {
// Connection refused.
if c.fallback != nil {
// XXX: this runs the PreRun twice
return c.fallback.Execute(req, re, env)
Expand Down Expand Up @@ -237,17 +244,3 @@ func getQuery(req *cmds.Request) (string, error) {

return query.Encode(), nil
}

func isConnRefused(err error) bool {
// unwrap url errors from http calls
if urlerr, ok := err.(*url.Error); ok {
err = urlerr.Err
}

netoperr, ok := err.(*net.OpError)
if !ok {
return false
}

return netoperr.Op == "dial"
}

0 comments on commit aa35dd1

Please sign in to comment.