You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ignite.apache.org by GitBox <gi...@apache.org> on 2022/06/30 12:49:20 UTC

[GitHub] [ignite-3] sk0x50 commented on a diff in pull request #890: IGNITE-17193: Return application/problem+json in REST

sk0x50 commented on code in PR #890:
URL: https://github.com/apache/ignite-3/pull/890#discussion_r910926972


##########
modules/cluster-management/src/main/java/org/apache/ignite/internal/cluster/management/rest/exception/handler/IgniteInternalExceptionHandler.java:
##########
@@ -20,23 +20,23 @@
 import io.micronaut.context.annotation.Requires;
 import io.micronaut.http.HttpRequest;
 import io.micronaut.http.HttpResponse;
-import io.micronaut.http.annotation.Produces;
 import io.micronaut.http.server.exceptions.ExceptionHandler;
 import jakarta.inject.Singleton;
-import org.apache.ignite.internal.rest.api.ErrorResult;
+import org.apache.ignite.internal.rest.api.Problem;
+import org.apache.ignite.internal.rest.problem.HttpProblemResponse;
 import org.apache.ignite.lang.IgniteInternalException;
 
 /**
  * Handles {@link IgniteInternalException} and represents it as a rest response.
  */
-@Produces
 @Singleton
 @Requires(classes = {IgniteInternalException.class, ExceptionHandler.class})
-public class IgniteInternalExceptionHandler implements ExceptionHandler<IgniteInternalException, HttpResponse<ErrorResult>> {
+public class IgniteInternalExceptionHandler implements ExceptionHandler<IgniteInternalException, HttpResponse<? extends Problem>> {

Review Comment:
   Looks like we need the same handler in order to handle `IgniteInternalCheckedException`



##########
modules/configuration-api/src/main/java/org/apache/ignite/configuration/validation/ValidationIssue.java:
##########
@@ -24,6 +24,9 @@
  * Class that stores information about issues found during the configuration validation.
  */
 public class ValidationIssue {
+    /** Configuration key. */
+    private final String key;

Review Comment:
   Please annotate this field with `@IgniteToStringInclude`



##########
modules/rest-api/src/main/java/org/apache/ignite/internal/rest/exception/handler/IgniteExceptionHandler.java:
##########
@@ -0,0 +1,72 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.rest.exception.handler;
+
+import io.micronaut.context.annotation.Requires;
+import io.micronaut.http.HttpRequest;
+import io.micronaut.http.HttpResponse;
+import io.micronaut.http.server.exceptions.ExceptionHandler;
+import jakarta.inject.Singleton;
+import java.util.List;
+import java.util.stream.Collectors;
+import org.apache.ignite.configuration.validation.ConfigurationValidationException;
+import org.apache.ignite.internal.rest.api.InvalidParam;
+import org.apache.ignite.internal.rest.api.Problem;
+import org.apache.ignite.internal.rest.api.ValidationProblem;
+import org.apache.ignite.internal.rest.constants.HttpCode;
+import org.apache.ignite.internal.rest.problem.HttpProblemResponse;
+import org.apache.ignite.lang.IgniteException;
+
+/**
+ * Handles {@link IgniteException} and represents it as an application/problem+json response.
+ */
+@Singleton
+@Requires(classes = {IgniteException.class, ExceptionHandler.class})
+public class IgniteExceptionHandler implements ExceptionHandler<IgniteException, HttpResponse<? extends Problem>> {

Review Comment:
   I think it will be needed to add a handler for `IgniteCheckedException` in nearest future.
   Please take a look at https://issues.apache.org/jira/browse/IGNITE-14931
   By the way, traceId will be introduced by IGNITE-14931 as well



##########
modules/configuration/src/test/java/org/apache/ignite/internal/configuration/validation/ValidationUtilTest.java:
##########
@@ -358,7 +358,7 @@ private static class ExValidationIssue extends ValidationIssue {
                 @Nullable Object oldVal,
                 Object newVal
         ) {
-            super(message);
+            super(currentKey, message);
             this.currentKey = currentKey;

Review Comment:
   We already have `currentKey` in the base class, so it can be removed from `ExValidationIssue` class.



##########
modules/rest-api/src/main/java/org/apache/ignite/internal/rest/api/Problem.java:
##########
@@ -0,0 +1,231 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.rest.api;
+
+import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonGetter;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import java.util.Objects;
+import java.util.UUID;
+import org.apache.ignite.internal.rest.constants.HttpCode;
+import org.apache.ignite.internal.rest.problem.Builder;
+
+/**
+ * Implements application/problem+json schema defined in <a href="https://www.rfc-editor.org/rfc/rfc7807.html">RFC-7807</a>.
+ */
+public class Problem {
+    /**
+     * Short, human-readable summary of the problem type.
+     */
+    private final String title;

Review Comment:
   It would be better to use single-line  javadoc here and below.



-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org