diff options
Diffstat (limited to 'vendor/gopkg.in/olivere/elastic.v5/errors.go')
-rw-r--r-- | vendor/gopkg.in/olivere/elastic.v5/errors.go | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/vendor/gopkg.in/olivere/elastic.v5/errors.go b/vendor/gopkg.in/olivere/elastic.v5/errors.go index e40cda845..2aeff6b4b 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/errors.go +++ b/vendor/gopkg.in/olivere/elastic.v5/errors.go @@ -5,10 +5,12 @@ package elastic import ( + "context" "encoding/json" "fmt" "io/ioutil" "net/http" + "net/url" "github.com/pkg/errors" ) @@ -86,9 +88,24 @@ type ErrorDetails struct { func (e *Error) Error() string { if e.Details != nil && e.Details.Reason != "" { return fmt.Sprintf("elastic: Error %d (%s): %s [type=%s]", e.Status, http.StatusText(e.Status), e.Details.Reason, e.Details.Type) - } else { - return fmt.Sprintf("elastic: Error %d (%s)", e.Status, http.StatusText(e.Status)) } + return fmt.Sprintf("elastic: Error %d (%s)", e.Status, http.StatusText(e.Status)) +} + +// IsContextErr returns true if the error is from a context that was canceled or deadline exceeded +func IsContextErr(err error) bool { + if err == context.Canceled || err == context.DeadlineExceeded { + return true + } + // This happens e.g. on redirect errors, see https://golang.org/src/net/http/client_test.go#L329 + if ue, ok := err.(*url.Error); ok { + if ue.Temporary() { + return true + } + // Use of an AWS Signing Transport can result in a wrapped url.Error + return IsContextErr(ue.Err) + } + return false } // IsConnErr returns true if the error indicates that Elastic could not |