From aa35dd12f49b5ef47f9cbf8382e9f258839f7b90 Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Wed, 21 Aug 2019 17:50:35 -0700 Subject: [PATCH] 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. --- http/client.go | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/http/client.go b/http/client.go index 3ac2925c..753f6a5b 100644 --- a/http/client.go +++ b/http/client.go @@ -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) @@ -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" -}