Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

http: cleanup http related errors #173

Merged
merged 1 commit into from
Aug 22, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"
}