sashapolo commented on a change in pull request #640:
URL: https://github.com/apache/ignite-3/pull/640#discussion_r801620886
##########
File path:
modules/rest/src/main/java/org/apache/ignite/internal/rest/RestModule.java
##########
@@ -232,34 +244,36 @@ private void handleRepresentByPath(
* @param res Rest response.
* @param presentation Configuration presentation.
*/
- private void handleUpdate(
+ private static CompletableFuture<RestApiHttpResponse> handleUpdate(
RestApiHttpRequest req,
RestApiHttpResponse res,
ConfigurationPresentation<String> presentation
) {
- try {
- String updateReq = req
- .request()
- .content()
- .readCharSequence(req.request().content().readableBytes(),
UTF_8)
- .toString();
-
- presentation.update(updateReq);
- } catch (IllegalArgumentException e) {
- ErrorResult errRes = new ErrorResult("INVALID_CONFIG_FORMAT",
e.getMessage());
-
- res.status(BAD_REQUEST);
- res.json(Map.of("error", errRes));
- } catch (ConfigurationValidationException e) {
- ErrorResult errRes = new ErrorResult("VALIDATION_EXCEPTION",
e.getMessage());
-
- res.status(BAD_REQUEST);
- res.json(Map.of("error", errRes));
- } catch (IgniteException e) {
- ErrorResult errRes = new ErrorResult("APPLICATION_EXCEPTION",
e.getMessage());
-
- res.status(BAD_REQUEST);
- res.json(Map.of("error", errRes));
- }
+ String updateReq =
req.request().content().toString(StandardCharsets.UTF_8);
+
+ return presentation.update(updateReq)
+ .thenApply(v -> res)
+ .exceptionally(e -> {
+ if (e instanceof CompletionException) {
+ e = e.getCause();
+ }
+
+ ErrorResult errRes;
+
+ if (e instanceof IllegalArgumentException) {
+ errRes = new ErrorResult("INVALID_CONFIG_FORMAT",
e.getMessage());
+ } else if (e instanceof ConfigurationValidationException) {
+ errRes = new ErrorResult("VALIDATION_EXCEPTION",
e.getMessage());
+ } else if (e instanceof IgniteException) {
+ errRes = new ErrorResult("APPLICATION_EXCEPTION",
e.getMessage());
+ } else {
+ throw new CompletionException(e);
+ }
+
+ res.status(BAD_REQUEST);
Review comment:
I agree, but it is not related to my changes and I would like to avoid
adding more code to this PR. Maybe we can incorporate this change in the
upcoming refactoring.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]