Watcher: Exeuting a watch returns a proper 404 (elastic/x-pack-elasticsearch#1273)
A test failure uncovered that handling non existing watches in the execute watch API could lead to 500 errors instead of 404 because they were not handled correctly. relates elastic/x-pack-elasticsearch#1120 Original commit: elastic/x-pack-elasticsearch@c17a07ae3e
This commit is contained in:
parent
ff6283bf80
commit
3a0bc504a9
|
@ -53,7 +53,7 @@ public class TransportAckWatchAction extends WatcherTransportAction<AckWatchRequ
|
|||
protected void doExecute(AckWatchRequest request, ActionListener<AckWatchResponse> listener) {
|
||||
client.getWatch(request.getWatchId(), ActionListener.wrap((response) -> {
|
||||
if (response.isExists() == false) {
|
||||
listener.onFailure(new ResourceNotFoundException("Watch with id [{}] does not exit", request.getWatchId()));
|
||||
listener.onFailure(new ResourceNotFoundException("Watch with id [{}] does not exist", request.getWatchId()));
|
||||
} else {
|
||||
DateTime now = new DateTime(clock.millis(), UTC);
|
||||
Watch watch = parser.parseWithSecrets(request.getWatchId(), true, response.getSourceAsBytesRef(), now, XContentType.JSON);
|
||||
|
|
|
@ -7,6 +7,7 @@ package org.elasticsearch.xpack.watcher.transport.actions.execute;
|
|||
|
||||
import org.apache.logging.log4j.message.ParameterizedMessage;
|
||||
import org.apache.logging.log4j.util.Supplier;
|
||||
import org.elasticsearch.ResourceNotFoundException;
|
||||
import org.elasticsearch.action.ActionListener;
|
||||
import org.elasticsearch.action.support.ActionFilters;
|
||||
import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver;
|
||||
|
@ -70,10 +71,14 @@ public class TransportExecuteWatchAction extends WatcherTransportAction<ExecuteW
|
|||
protected void doExecute(ExecuteWatchRequest request, ActionListener<ExecuteWatchResponse> listener) {
|
||||
if (request.getId() != null) {
|
||||
client.getWatch(request.getId(), ActionListener.wrap(response -> {
|
||||
Watch watch = watchParser.parse(request.getId(), true, response.getSourceAsBytesRef(), request.getXContentType());
|
||||
watch.version(response.getVersion());
|
||||
watch.status().version(response.getVersion());
|
||||
executeWatch(request, listener, watch, true);
|
||||
if (response.isExists()) {
|
||||
Watch watch = watchParser.parse(request.getId(), true, response.getSourceAsBytesRef(), request.getXContentType());
|
||||
watch.version(response.getVersion());
|
||||
watch.status().version(response.getVersion());
|
||||
executeWatch(request, listener, watch, true);
|
||||
} else {
|
||||
listener.onFailure(new ResourceNotFoundException("Watch with id [{}] does not exist", request.getId()));
|
||||
}
|
||||
}, listener::onFailure));
|
||||
} else if (request.getWatchSource() != null) {
|
||||
try {
|
||||
|
|
Loading…
Reference in New Issue