Skip to content

Commit

Permalink
feat(errors): add IsConflict checker (#562)
Browse files Browse the repository at this point in the history
  • Loading branch information
connor4312 authored and olivere committed Jul 18, 2017
1 parent 99e76ec commit 5b4cd4e
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions errors.go
Expand Up @@ -123,6 +123,25 @@ func IsTimeout(err interface{}) bool {
return false
}

// 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 {
switch e := err.(type) {
case *http.Response:
return e.StatusCode == http.StatusConflict
case *Error:
return e.Status == http.StatusConflict
case Error:
return e.Status == http.StatusConflict
case int:
return e == http.StatusConflict
}
return false
}

// -- General errors --

// shardsInfo represents information from a shard.
Expand Down

0 comments on commit 5b4cd4e

Please sign in to comment.