dimas-b commented on code in PR #864:
URL: https://github.com/apache/polaris/pull/864#discussion_r1929391230
##########
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 proposes this mapping:
Storage -> Client
* 3xx -> 502 : redirects mean the server is not able to properly "proxy"
storage data, but this is unlikely to be caused by mistakes in the current
request, hence "bad gateway".
* 404 -> 400 : something not found in storage is likely due to mistakes in
the submitted data, but we cannot assume the the requested Polaris entity is
simply not found.
* 400 -> 400 : bad storage request is likely due to mistakes in the
submitted data.
* 401 -> 403 : incorrect authentication settings for storage mean the client
is denied access to the related Polaris entity, but we cannot flag that the
client did not provide correct authentication in its request to Polaris.
* 403 -> 403 : denied access to storage means the client is denied access to
the related Polaris entity.
* 429 -> 429 (throttling)
* default -> 500
--
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]