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


##########
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:
   Added the `NOT_IN_USE_CODE` mapping to preserve `CatalogNotInUseException` 
and `MetalakeNotInUseException`, with `NotInUseException` as the fallback. The 
client error-mapping test now covers all three cases through HTTP 409 responses.



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