Copilot commented on code in PR #12628:
URL: https://github.com/apache/gravitino/pull/12628#discussion_r4244385814


##########
clients/client-java/src/main/java/org/apache/gravitino/client/ErrorHandlers.java:
##########
@@ -1497,4 +1509,61 @@ public void accept(ErrorResponse errorResponse) {
       }
     }
   }
+
+  /** Error handler specific to Semantic Model operations. */
+  @SuppressWarnings("FormatStringAnnotation")
+  private static class SemanticModelErrorHandler extends RestErrorHandler {
+
+    private static final SemanticModelErrorHandler INSTANCE = new 
SemanticModelErrorHandler();
+
+    @Override
+    public void accept(ErrorResponse errorResponse) {
+      String errorMessage = formatErrorMessage(errorResponse);
+
+      switch (errorResponse.getCode()) {
+        case ErrorConstants.ILLEGAL_ARGUMENTS_CODE:
+          if 
(IllegalSemanticModelException.class.getSimpleName().equals(errorResponse.getType()))
 {
+            throw new IllegalSemanticModelException(errorMessage);
+          }
+          throw new IllegalArgumentException(errorMessage);
+
+        case ErrorConstants.NOT_FOUND_CODE:
+          if 
(NoSuchMetalakeException.class.getSimpleName().equals(errorResponse.getType())) 
{
+            throw new NoSuchMetalakeException(errorMessage);
+          } else if 
(NoSuchCatalogException.class.getSimpleName().equals(errorResponse.getType())) {
+            throw new NoSuchCatalogException(errorMessage);
+          } else if 
(NoSuchSchemaException.class.getSimpleName().equals(errorResponse.getType())) {
+            throw new NoSuchSchemaException(errorMessage);
+          } else if (NoSuchSemanticModelException.class
+              .getSimpleName()
+              .equals(errorResponse.getType())) {
+            throw new NoSuchSemanticModelException(errorMessage);
+          }
+          throw new NotFoundException(errorMessage);
+
+        case ErrorConstants.ALREADY_EXISTS_CODE:
+          if (SemanticModelAlreadyExistsException.class
+              .getSimpleName()
+              .equals(errorResponse.getType())) {
+            throw new SemanticModelAlreadyExistsException(errorMessage);
+          }
+          throw new AlreadyExistsException(errorMessage);
+
+        case ErrorConstants.UNSUPPORTED_OPERATION_CODE:
+          throw new UnsupportedOperationException(errorMessage);
+
+        case ErrorConstants.FORBIDDEN_CODE:
+          throw new ForbiddenException(errorMessage);
+
+        case ErrorConstants.INTERNAL_ERROR_CODE:
+          throw new RuntimeException(errorMessage);
+
+        case ErrorConstants.OPTIMISTIC_LOCK_CONFLICT_CODE:
+          throw new OptimisticLockException(errorMessage);
+
+        default:

Review Comment:
   Handle `NOT_IN_USE_CODE` before delegating to `RestErrorHandler`. The server 
explicitly emits this code for Semantic Model operations when a catalog or 
metalake is not in use (`ExceptionHandlers.java:1039-1043`), but the fallback 
turns it into a generic `RESTException`; the other catalog-specific handlers 
preserve `CatalogNotInUseException`, `MetalakeNotInUseException`, or 
`NotInUseException`. Add the same mapping here and cover it in the 
error-mapping test.



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