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


##########
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:
   nit: maybe refactor storage exception handling into a separate (private) 
method?



##########
service/common/src/main/java/org/apache/polaris/service/exception/IcebergExceptionMapper.java:
##########
@@ -144,4 +113,71 @@ 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 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;
+          };
+      Status httpStatus = Status.fromStatusCode(httpCode);
+
+      if (Status.Family.familyOf(httpCode) == Status.Family.REDIRECTION) {
+        return Status.BAD_GATEWAY.getStatusCode();
+      }
+      if (Status.Family.familyOf(httpCode) == Status.Family.SERVER_ERROR) {
+        return Status.INTERNAL_SERVER_ERROR.getStatusCode();

Review Comment:
   Since we treat this as a special case, I'd actually convert storage 5xx to 
client 502 (Bad Gateway). I think this matches HTTP error code definitions 
exactly.



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