Skip to content

Commit 76e8e6a

Browse files
committed
Change Elasticsearch timeouts to 429 response instead of 500
When a user passes a timeout to an Elasticsearch request, the user is telling the system to limit how long the request should take. If that timeout is breached, it is because the user selected a timeout less than the time the request needs. Therefore, it is up to the user to select a long enough time. If they don't, it's on the user to adjust their request. Given the above, a breached timeout is an issue with the user request, and the http response code should refelect that. This commit changes timeout exceptions to give a 429 response code instead of the default 500.
1 parent 3cbbcc5 commit 76e8e6a

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

server/src/main/java/org/elasticsearch/ElasticsearchTimeoutException.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
package org.elasticsearch;
1111

1212
import org.elasticsearch.common.io.stream.StreamInput;
13+
import org.elasticsearch.rest.RestStatus;
1314

1415
import java.io.IOException;
1516

@@ -34,4 +35,10 @@ public ElasticsearchTimeoutException(String message, Object... args) {
3435
public ElasticsearchTimeoutException(String message, Throwable cause, Object... args) {
3536
super(message, cause, args);
3637
}
38+
39+
@Override
40+
public RestStatus status() {
41+
// closest thing to "your request took longer than you asked for"
42+
return RestStatus.TOO_MANY_REQUESTS;
43+
}
3744
}

0 commit comments

Comments
 (0)