summaryrefslogtreecommitdiffstats
path: root/vespaclient-container-plugin
diff options
context:
space:
mode:
authorJon Bratseth <bratseth@verizonmedia.com>2019-04-26 16:21:48 +0200
committerJon Bratseth <bratseth@verizonmedia.com>2019-04-26 16:21:48 +0200
commitdf35969143c0edcdb08d4471e56e02077b8c7934 (patch)
treeab44c9c33d04f8bf407f1838f53d3817d1f4b7ea /vespaclient-container-plugin
parent4564507a491b5497b5d60ecc0305e5a017ab5c46 (diff)
Separate user and system exceptions
Diffstat (limited to 'vespaclient-container-plugin')
-rw-r--r--vespaclient-container-plugin/src/main/java/com/yahoo/document/restapi/resource/RestApi.java17
1 files changed, 11 insertions, 6 deletions
diff --git a/vespaclient-container-plugin/src/main/java/com/yahoo/document/restapi/resource/RestApi.java b/vespaclient-container-plugin/src/main/java/com/yahoo/document/restapi/resource/RestApi.java
index 873b0569553..6fed0dff36d 100644
--- a/vespaclient-container-plugin/src/main/java/com/yahoo/document/restapi/resource/RestApi.java
+++ b/vespaclient-container-plugin/src/main/java/com/yahoo/document/restapi/resource/RestApi.java
@@ -36,6 +36,7 @@ import com.yahoo.vespaclient.ClusterList;
import com.yahoo.vespaxmlparser.DocumentFeedOperation;
import com.yahoo.vespaxmlparser.FeedOperation;
import com.yahoo.vespaxmlparser.VespaXMLFeedReader;
+import com.yahoo.yolean.Exceptions;
import java.io.IOException;
import java.io.OutputStream;
@@ -230,10 +231,14 @@ public class RestApi extends LoggingRequestHandler {
}
} catch (RestApiException e) {
return e.getResponse();
- } catch (Exception e2) {
- // We always blame the user. This might be a bit nasty, but the parser throws various kind of exception
- // types, but with nice descriptions.
- return Response.createErrorResponse(400, e2.getMessage(), restUri, RestUri.apiErrorCodes.PARSER_ERROR);
+ } catch (IllegalArgumentException userException) {
+ return Response.createErrorResponse(400, Exceptions.toMessageString(userException),
+ restUri,
+ RestUri.apiErrorCodes.PARSER_ERROR);
+ } catch (RuntimeException systemException) {
+ return Response.createErrorResponse(500, Exceptions.toMessageString(systemException),
+ restUri,
+ RestUri.apiErrorCodes.PARSER_ERROR);
}
return new Response(200, resultJson, Optional.of(restUri));
}
@@ -401,8 +406,8 @@ public class RestApi extends LoggingRequestHandler {
} catch (BadRequestParameterException e) {
return createInvalidParameterResponse(e.getParameter(), e.getMessage());
}
- final OperationHandler.VisitResult visit = operationHandler.visit(restUri, documentSelection, options);
- final ObjectNode resultNode = mapper.createObjectNode();
+ OperationHandler.VisitResult visit = operationHandler.visit(restUri, documentSelection, options);
+ ObjectNode resultNode = mapper.createObjectNode();
visit.token.ifPresent(t -> resultNode.put(CONTINUATION, t));
resultNode.putArray(DOCUMENTS).addPOJO(visit.documentsAsJsonList);
resultNode.put(PATH_NAME, restUri.getRawPath());