rpuch commented on a change in pull request #640:
URL: https://github.com/apache/ignite-3/pull/640#discussion_r801610850



##########
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:
       `BAD_REQUEST` is for the cases when input is invalid. 
`ConfigurationValidationException` and `IllegalArgumentException` seem to fit 
this, but what if a handler throws an exception unrelated to validation? In 
such case `BAD_REQUEST` does not seem suitable.
   
   I suggest to choose the status based on the exception class: if it's related 
to validation, then we return 400, otherwise 500. Later the assortment of the 
possible codes could be expanded.

##########
File path: 
modules/rest/src/main/java/org/apache/ignite/internal/rest/netty/RestApiInitializer.java
##########
@@ -46,7 +45,6 @@ public RestApiInitializer(Router router) {
     public void initChannel(SocketChannel ch) {
         ChannelPipeline p = ch.pipeline();
         p.addLast(new HttpServerCodec());
-        p.addLast(new HttpServerExpectContinueHandler());

Review comment:
       Hmm.. don't we need Expect/Continue anymore? Is this somehow connected 
with the introduced asynchrony?




-- 
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]


Reply via email to