Skip to content

Commit b5b6d88

Browse files
committed
Throw NotFoundException if the requested entity_type does not exist when submitting a resolution job. Fixes a vague NullPointerException.
1 parent 79a00e3 commit b5b6d88

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

Diff for: src/main/java/org/elasticsearch/plugin/zentity/ResolutionAction.java

+11-3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import io.zentity.model.ValidationException;
55
import io.zentity.resolution.Job;
66
import io.zentity.resolution.input.Input;
7+
import org.elasticsearch.action.get.GetResponse;
78
import org.elasticsearch.client.node.NodeClient;
89
import org.elasticsearch.common.inject.Inject;
910
import org.elasticsearch.common.settings.Settings;
@@ -55,10 +56,15 @@ protected RestChannelConsumer prepareRequest(RestRequest restRequest, NodeClient
5556

5657
// Parse and validate the job input.
5758
Input input;
58-
if (entityType == null || entityType.equals(""))
59+
if (entityType == null || entityType.equals("")) {
5960
input = new Input(body, entityType);
60-
else
61-
input = new Input(body, new Model(ModelsAction.getEntityModel(entityType, client).getSourceAsString()));
61+
} else {
62+
GetResponse getResponse = ModelsAction.getEntityModel(entityType, client);
63+
if (!getResponse.isExists())
64+
throw new NotFoundException("Entity type '" + entityType + "' not found.");
65+
String model = getResponse.getSourceAsString();
66+
input = new Input(body, new Model(model));
67+
}
6268
if (input.attributes().isEmpty())
6369
throw new ValidationException("'attributes' is missing.");
6470
if (input.model() == null)
@@ -82,6 +88,8 @@ protected RestChannelConsumer prepareRequest(RestRequest restRequest, NodeClient
8288

8389
} catch (ValidationException e) {
8490
channel.sendResponse(new BytesRestResponse(channel, RestStatus.BAD_REQUEST, e));
91+
} catch (NotFoundException e) {
92+
channel.sendResponse(new BytesRestResponse(channel, RestStatus.NOT_FOUND, e));
8593
}
8694
};
8795
}

0 commit comments

Comments
 (0)