mchades commented on code in PR #12625:
URL: https://github.com/apache/gravitino/pull/12625#discussion_r4118823100


##########
server/src/main/java/org/apache/gravitino/server/web/rest/ExceptionHandlers.java:
##########
@@ -990,6 +1005,46 @@ public Response handle(OperationType op, String function, 
String schema, Excepti
     }
   }
 
+  private static class SemanticModelExceptionHandler extends 
BaseExceptionHandler {
+    private static final ExceptionHandler INSTANCE = new 
SemanticModelExceptionHandler();
+
+    private static String getSemanticModelErrorMsg(
+        String semanticModel, String operation, String schema, String reason) {
+      return String.format(
+          "Failed to operate Semantic Model(s)%s operation [%s] under schema 
[%s], reason [%s]",
+          semanticModel, operation, schema, reason);
+    }
+
+    @Override
+    public Response handle(OperationType op, String semanticModel, String 
schema, Exception e) {
+      String formatted = StringUtil.isBlank(semanticModel) ? "" : " [" + 
semanticModel + "]";
+      String errorMsg = getSemanticModelErrorMsg(formatted, op.name(), schema, 
getErrorMsg(e));
+      LOG.warn(errorMsg, e);
+
+      if (e instanceof IllegalArgumentException) {
+        return Utils.illegalArguments(errorMsg, e);
+
+      } else if (e instanceof NotFoundException) {
+        return Utils.notFound(errorMsg, e);
+
+      } else if (e instanceof SemanticModelAlreadyExistsException) {
+        return Utils.alreadyExists(errorMsg, e);
+
+      } else if (e instanceof ForbiddenException) {
+        return Utils.forbidden(errorMsg, e);
+
+      } else if (e instanceof UnsupportedOperationException) {
+        return Utils.unsupportedOperation(errorMsg, e);
+
+      } else if (e instanceof ConnectionFailedException) {
+        return Utils.connectionFailed(errorMsg, e);

Review Comment:
   These branches are not behaviorally redundant. The direct mappings preserve 
the Semantic Model-specific error message. Falling through to 
`BaseExceptionHandler` rebuilds a generic `Failed to operate object...` message 
and logs the same exception again.
   
   The HTTP status and application error code would remain 501/502, but the 
response message and logging would change, so I’ll keep the explicit branches.



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