andrew4699 commented on code in PR #864:
URL: https://github.com/apache/polaris/pull/864#discussion_r1929036914
##########
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 thought a bit about this and originally was turning these all into 400s,
but landed on this for a few reasons:
1. Polaris is effectively acting as a proxy to their storage service, so
it's not unreasonable that it would return an error close to what the storage
service returns.
2. Storage credentials/paths are usually configured at a different
point-in-time than the request that fails, so calling the subsequent request a
"bad request" isn't so accurate.
3. Can make it easier for users to distinguish errors
4. Still maintains the spirit of errors in the 3xx/4xx range
That said, if we want to follow the REST Catalog
[spec](https://github.com/apache/iceberg/blob/main/open-api/rest-catalog-open-api.yaml)
more closely, I propose we can do the following:
- 3xx => 400
- 401 => 401
- 403 => 403
- 404 => 404
- Other 4xx => 400
--
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]