aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJon Bratseth <bratseth@oath.com>2018-09-18 16:27:23 -0700
committerJon Bratseth <bratseth@oath.com>2018-09-18 16:27:23 -0700
commita172868b098df9cf7e49a177544b59529202b71d (patch)
treee39e56cdac42e772bdcbcf07e7756c977d87b8be
parentd7e615634d975431cf753cd7a15cd8a07b4c8275 (diff)
Change return codes from 400 to 404
-rw-r--r--model-evaluation/src/main/java/ai/vespa/models/handler/ModelsEvaluationHandler.java16
-rw-r--r--model-evaluation/src/test/java/ai/vespa/models/handler/ModelsEvaluationHandlerTest.java8
2 files changed, 14 insertions, 10 deletions
diff --git a/model-evaluation/src/main/java/ai/vespa/models/handler/ModelsEvaluationHandler.java b/model-evaluation/src/main/java/ai/vespa/models/handler/ModelsEvaluationHandler.java
index 48011c7e6b6..1c995c255f5 100644
--- a/model-evaluation/src/main/java/ai/vespa/models/handler/ModelsEvaluationHandler.java
+++ b/model-evaluation/src/main/java/ai/vespa/models/handler/ModelsEvaluationHandler.java
@@ -40,22 +40,24 @@ public class ModelsEvaluationHandler extends ThreadedHttpRequestHandler {
Optional<String> modelName = path.segment(2);
if ( ! apiName.isPresent() || ! apiName.get().equalsIgnoreCase(API_ROOT)) {
- return new ErrorResponse(400, "unknown API");
+ return new ErrorResponse(404, "unknown API");
}
if ( ! version.isPresent() || ! version.get().equalsIgnoreCase(VERSION_V1)) {
- return new ErrorResponse(400, "unknown API version");
+ return new ErrorResponse(404, "unknown API version");
}
if ( ! modelName.isPresent()) {
return listAllModels(request);
}
if ( ! modelsEvaluator.models().containsKey(modelName.get())) {
- return new ErrorResponse(400, "no model with name '" + modelName.get() + "' found");
+ // TODO: Replace by catching IllegalArgumentException and passing that error message
+ return new ErrorResponse(404, "no model with name '" + modelName.get() + "' found");
}
Model model = modelsEvaluator.models().get(modelName.get());
// The following logic follows from the spec, in that signature and
// output are optional if the model only has a single function.
+ // TODO: Try to avoid recreating that logic here
if (path.segments() == 3) {
if (model.functions().size() > 1) {
@@ -74,7 +76,8 @@ public class ModelsEvaluationHandler extends ThreadedHttpRequestHandler {
if (model.functions().size() <= 1) {
return evaluateModel(request, modelName.get());
}
- return new ErrorResponse(400, "attempt to evaluate model without specifying function");
+ // TODO: Replace by catching IllegalArgumentException and passing that error message
+ return new ErrorResponse(404, "attempt to evaluate model without specifying function");
}
if (path.segments() == 5) {
@@ -83,7 +86,7 @@ public class ModelsEvaluationHandler extends ThreadedHttpRequestHandler {
}
}
- return new ErrorResponse(400, "unrecognized request");
+ return new ErrorResponse(404, "unrecognized request");
}
private HttpResponse listAllModels(HttpRequest request) {
@@ -118,6 +121,7 @@ public class ModelsEvaluationHandler extends ThreadedHttpRequestHandler {
Cursor root = slime.setObject();
Cursor bindings = root.setArray("bindings");
for (String bindingName : evaluator.context().names()) {
+ // TODO: Use an API which exposes only the external binding names instead of this
if (bindingName.startsWith("constant(")) {
continue;
}
@@ -126,7 +130,7 @@ public class ModelsEvaluationHandler extends ThreadedHttpRequestHandler {
}
Cursor binding = bindings.addObject();
binding.setString("name", bindingName);
- binding.setString("type", ""); // todo: implement type information when available
+ binding.setString("type", ""); // TODO: implement type information when available
}
return new Response(200, com.yahoo.slime.JsonFormat.toJsonBytes(slime));
}
diff --git a/model-evaluation/src/test/java/ai/vespa/models/handler/ModelsEvaluationHandlerTest.java b/model-evaluation/src/test/java/ai/vespa/models/handler/ModelsEvaluationHandlerTest.java
index 9966fd3d88e..5f045a2feb4 100644
--- a/model-evaluation/src/test/java/ai/vespa/models/handler/ModelsEvaluationHandlerTest.java
+++ b/model-evaluation/src/test/java/ai/vespa/models/handler/ModelsEvaluationHandlerTest.java
@@ -37,17 +37,17 @@ public class ModelsEvaluationHandlerTest {
@Test
public void testUnknownAPI() {
- assertResponse("http://localhost/wrong-api-binding", 400);
+ assertResponse("http://localhost/wrong-api-binding", 404);
}
@Test
public void testUnknownVersion() {
- assertResponse("http://localhost/model-evaluation/v0", 400);
+ assertResponse("http://localhost/model-evaluation/v0", 404);
}
@Test
public void testNonExistingModel() {
- assertResponse("http://localhost/model-evaluation/v1/non-existing-model", 400);
+ assertResponse("http://localhost/model-evaluation/v1/non-existing-model", 404);
}
@Test
@@ -141,7 +141,7 @@ public class ModelsEvaluationHandlerTest {
public void testMnistSavedEvaluateDefaultFunctionShouldFail() {
String url = "http://localhost/model-evaluation/v1/mnist_saved/eval";
String expected = "{\"error\":\"attempt to evaluate model without specifying function\"}";
- assertResponse(url, 400, expected);
+ assertResponse(url, 404, expected);
}
@Test