Skip to content

Commit

Permalink
use entityexistsexception
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-maynard committed Sep 6, 2024
1 parent 51195b0 commit e82a4a1
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import static org.eclipse.persistence.config.PersistenceUnitProperties.JDBC_URL;

import com.google.common.base.Predicates;
import jakarta.persistence.EntityExistsException;
import jakarta.persistence.EntityManager;
import jakarta.persistence.EntityManagerFactory;
import jakarta.persistence.EntityTransaction;
Expand Down Expand Up @@ -261,7 +262,7 @@ public <T> T runInTransaction(
}
} catch (PersistenceException e) {
if (e.toString().toLowerCase(Locale.ROOT).contains("duplicate key")) {
throw new IllegalStateException("Duplicate key error when persisting entity", e);
throw new EntityExistsException("Duplicate key error when persisting entity", e);
} else {
throw e;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -360,11 +360,7 @@ public Response assignPrincipalRole(
request.getPrincipalRole().getName(),
principalName);
PolarisAdminService adminService = newAdminService(securityContext);
try {
adminService.assignPrincipalRole(principalName, request.getPrincipalRole().getName());
} catch (IllegalStateException e) {
throw new AlreadyExistsException("Grant already exists or resolution failed");
}
adminService.assignPrincipalRole(principalName, request.getPrincipalRole().getName());
return Response.status(Response.Status.CREATED).build();
}

Expand Down Expand Up @@ -406,12 +402,8 @@ public Response assignCatalogRoleToPrincipalRole(
catalogName,
principalRoleName);
PolarisAdminService adminService = newAdminService(securityContext);
try {
adminService.assignCatalogRoleToPrincipalRole(
principalRoleName, catalogName, request.getCatalogRole().getName());
} catch (IllegalStateException e) {
throw new AlreadyExistsException("Grant already exists or resolution failed");
}
adminService.assignCatalogRoleToPrincipalRole(
principalRoleName, catalogName, request.getCatalogRole().getName());
return Response.status(Response.Status.CREATED).build();
}

Expand Down

0 comments on commit e82a4a1

Please sign in to comment.