dimas-b commented on code in PR #864:
URL: https://github.com/apache/polaris/pull/864#discussion_r1927792648


##########
service/common/src/main/java/org/apache/polaris/service/exception/IcebergExceptionMapper.java:
##########
@@ -144,4 +112,56 @@ public static boolean containsAnyAccessDeniedHint(String 
message) {
   public static Collection<String> getAccessDeniedHints() {
     return ImmutableSet.copyOf(ACCESS_DENIED_HINTS);
   }
+
+  static int mapExceptionToResponseCode(RuntimeException rex) {
+    // Cloud exceptions
+    if (rex instanceof S3Exception
+        || rex instanceof AzureException
+        || rex instanceof StorageException) {

Review Comment:
   Why bother with complex logic when we have a typed switch below?



##########
quarkus/service/src/test/java/org/apache/polaris/service/quarkus/IcebergExceptionMapperTest.java:
##########
@@ -52,4 +68,17 @@ void fileIOExceptionMapping(RuntimeException ex, int 
statusCode) {
       
assertThat(response.getEntity()).extracting("message").isEqualTo(ex.getMessage());
     }
   }
+
+  /**
+   * Creates a mock of the Azure-specific HttpResponse object, as it's quite 
difficult to construct
+   * a "real" one.
+   *
+   * @param statusCode
+   * @return
+   */
+  private static HttpResponse mockAzureResponse(int statusCode) {
+    HttpResponse res = mock(HttpResponse.class);
+    when(res.getStatusCode()).thenReturn(statusCode);
+    return res;
+  }

Review Comment:
   What makes it specific to Azure?



##########
service/common/src/main/java/org/apache/polaris/service/exception/IcebergExceptionMapper.java:
##########
@@ -144,4 +112,56 @@ public static boolean containsAnyAccessDeniedHint(String 
message) {
   public static Collection<String> getAccessDeniedHints() {
     return ImmutableSet.copyOf(ACCESS_DENIED_HINTS);
   }
+
+  static int mapExceptionToResponseCode(RuntimeException rex) {
+    // Cloud exceptions
+    if (rex instanceof S3Exception
+        || rex instanceof AzureException
+        || rex instanceof StorageException) {
+      if (doesAnyThrowableContainAccessDeniedHint(rex)) {
+        return Response.Status.FORBIDDEN.getStatusCode();
+      }
+
+      int httpCode =
+          switch (rex) {
+            case S3Exception s3e -> s3e.statusCode();
+            case HttpResponseException hre -> 
hre.getResponse().getStatusCode();
+            case StorageException se -> se.getCode();
+            default -> -1;
+          };
+
+      if (300 <= httpCode && httpCode <= 499) {
+        return httpCode;

Review Comment:
   I'm not sure that (for example) a 301 (Moved Permanently) response at the 
storage level is correct to propagate to the Polaris client "as is".



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