Skip to content

Commit

Permalink
Deriving the REST status code from a failure can, very rarely, cause …
Browse files Browse the repository at this point in the history
…an infinite loop

fixes elastic#2402
  • Loading branch information
kimchy committed Nov 12, 2012
1 parent f849238 commit 486852a
Showing 1 changed file with 7 additions and 15 deletions.
22 changes: 7 additions & 15 deletions src/main/java/org/elasticsearch/ElasticSearchException.java
Expand Up @@ -23,8 +23,6 @@

/**
* A base class for all elasticsearch exceptions.
*
*
*/
public class ElasticSearchException extends RuntimeException {

Expand Down Expand Up @@ -52,21 +50,15 @@ public ElasticSearchException(String msg, Throwable cause) {
* Returns the rest status code associated with this exception.
*/
public RestStatus status() {
ElasticSearchException current = this;
while (current instanceof ElasticSearchWrapperException) {
if (getCause() == null) {
break;
}
if (getCause() instanceof ElasticSearchException) {
current = (ElasticSearchException) getCause();
} else {
break;
}
}
if (current == this) {
Throwable cause = unwrapCause();
if (cause == this) {
return RestStatus.INTERNAL_SERVER_ERROR;
} else if (cause instanceof ElasticSearchException) {
return ((ElasticSearchException) cause).status();
} else if (cause instanceof IllegalArgumentException) {
return RestStatus.BAD_REQUEST;
} else {
return current.status();
return RestStatus.INTERNAL_SERVER_ERROR;
}
}

Expand Down

0 comments on commit 486852a

Please sign in to comment.