diff options
author | Christopher Speller <crspeller@gmail.com> | 2017-07-20 15:22:49 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-07-20 15:22:49 -0700 |
commit | 58839cefb50e56ae5b157b37e9814ae83ceee70b (patch) | |
tree | 5de966481678096fc9567f74f96673b34a65127c /vendor/gopkg.in/olivere/elastic.v5/errors.go | |
parent | e2f4492eadb5d3c58606b1fdd5774b63a07c236a (diff) | |
download | chat-58839cefb50e56ae5b157b37e9814ae83ceee70b.tar.gz chat-58839cefb50e56ae5b157b37e9814ae83ceee70b.tar.bz2 chat-58839cefb50e56ae5b157b37e9814ae83ceee70b.zip |
Upgrading server dependancies (#6984)
Diffstat (limited to 'vendor/gopkg.in/olivere/elastic.v5/errors.go')
-rw-r--r-- | vendor/gopkg.in/olivere/elastic.v5/errors.go | 36 |
1 files changed, 21 insertions, 15 deletions
diff --git a/vendor/gopkg.in/olivere/elastic.v5/errors.go b/vendor/gopkg.in/olivere/elastic.v5/errors.go index 009123531..00a936621 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/errors.go +++ b/vendor/gopkg.in/olivere/elastic.v5/errors.go @@ -93,32 +93,38 @@ func (e *Error) Error() string { // returned HTTP status 404. The err parameter can be of type *elastic.Error, // elastic.Error, *http.Response or int (indicating the HTTP status code). func IsNotFound(err interface{}) bool { - switch e := err.(type) { - case *http.Response: - return e.StatusCode == http.StatusNotFound - case *Error: - return e.Status == http.StatusNotFound - case Error: - return e.Status == http.StatusNotFound - case int: - return e == http.StatusNotFound - } - return false + return IsStatusCode(err, http.StatusNotFound) } // IsTimeout returns true if the given error indicates that Elasticsearch // returned HTTP status 408. The err parameter can be of type *elastic.Error, // elastic.Error, *http.Response or int (indicating the HTTP status code). func IsTimeout(err interface{}) bool { + return IsStatusCode(err, http.StatusRequestTimeout) +} + +// IsConflict returns true if the given error indicates that the Elasticsearch +// operation resulted in a version conflict. This can occur in operations like +// `update` or `index` with `op_type=create`. The err parameter can be of +// type *elastic.Error, elastic.Error, *http.Response or int (indicating the +// HTTP status code). +func IsConflict(err interface{}) bool { + return IsStatusCode(err, http.StatusConflict) +} + +// IsStatusCode returns true if the given error indicates that the Elasticsearch +// operation returned the specified HTTP status code. The err parameter can be of +// type *http.Response, *Error, Error, or int (indicating the HTTP status code). +func IsStatusCode(err interface{}, code int) bool { switch e := err.(type) { case *http.Response: - return e.StatusCode == http.StatusRequestTimeout + return e.StatusCode == code case *Error: - return e.Status == http.StatusRequestTimeout + return e.Status == code case Error: - return e.Status == http.StatusRequestTimeout + return e.Status == code case int: - return e == http.StatusRequestTimeout + return e == code } return false } |