Skip to content

Commit

Permalink
better catch
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-maynard committed Sep 6, 2024
1 parent 51195b0 commit b4cf091
Showing 1 changed file with 17 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import jakarta.ws.rs.core.Response;
import jakarta.ws.rs.core.SecurityContext;
import java.util.List;
import java.util.Locale;

import org.apache.iceberg.catalog.Namespace;
import org.apache.iceberg.catalog.TableIdentifier;
import org.apache.iceberg.exceptions.AlreadyExistsException;
Expand Down Expand Up @@ -363,7 +365,11 @@ public Response assignPrincipalRole(
try {
adminService.assignPrincipalRole(principalName, request.getPrincipalRole().getName());
} catch (IllegalStateException e) {
throw new AlreadyExistsException("Grant already exists or resolution failed");
if (e.toString().toLowerCase(Locale.ROOT).contains("duplicate key")) {
throw new AlreadyExistsException("Grant already exists or resolution failed");
} else {
throw e;
}
}
return Response.status(Response.Status.CREATED).build();
}
Expand Down Expand Up @@ -410,7 +416,11 @@ public Response assignCatalogRoleToPrincipalRole(
adminService.assignCatalogRoleToPrincipalRole(
principalRoleName, catalogName, request.getCatalogRole().getName());
} catch (IllegalStateException e) {
throw new AlreadyExistsException("Grant already exists or resolution failed");
if (e.toString().toLowerCase(Locale.ROOT).contains("duplicate key")) {
throw new AlreadyExistsException("Grant already exists or resolution failed");
} else {
throw e;
}
}
return Response.status(Response.Status.CREATED).build();
}
Expand Down Expand Up @@ -531,7 +541,11 @@ public Response addGrantToCatalogRole(
return Response.status(Response.Status.BAD_REQUEST).build();
}
} catch (IllegalStateException e) {
throw new AlreadyExistsException("Grant already exists or resolution failed");
if (e.toString().toLowerCase(Locale.ROOT).contains("duplicate key")) {
throw new AlreadyExistsException("Grant already exists or resolution failed");
} else {
throw e;
}
}
return Response.status(Response.Status.CREATED).build();
}
Expand Down

0 comments on commit b4cf091

Please sign in to comment.