Skip to content

Commit 6db0c31

Browse files
committed
fix: fixing tests by proper exception handling
1 parent 90750e1 commit 6db0c31

1 file changed

Lines changed: 14 additions & 8 deletions

File tree

  • src/main/java/io/supertokens/storage/postgresql

src/main/java/io/supertokens/storage/postgresql/Start.java

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3596,15 +3596,21 @@ public void addBulkImportUsers(AppIdentifier appIdentifier, List<BulkImportUser>
35963596
try {
35973597
BulkImportQueries.insertBulkImportUsers_Transaction(this, (Connection) con.getConnection(), appIdentifier, users);
35983598
} catch (SQLException e) {
3599-
if (e instanceof PSQLException) {
3600-
ServerErrorMessage serverErrorMessage = ((PSQLException) e).getServerErrorMessage();
3601-
if (isPrimaryKeyError(serverErrorMessage, Config.getConfig(this).getBulkImportUsersTable())) {
3602-
throw new StorageTransactionLogicException(new io.supertokens.pluginInterface.bulkimport.exceptions.DuplicateUserIdException());
3603-
}
3604-
if (isForeignKeyConstraintError(serverErrorMessage, Config.getConfig(this).getBulkImportUsersTable(),
3605-
"app_id")) {
3606-
throw new TenantOrAppNotFoundException(appIdentifier);
3599+
if (e instanceof BatchUpdateException) {
3600+
BatchUpdateException batchUpdateException = (BatchUpdateException) e;
3601+
Map<String, Exception> errorByPosition = new HashMap<>();
3602+
SQLException nextException = batchUpdateException.getNextException();
3603+
if(nextException instanceof PSQLException){
3604+
ServerErrorMessage serverErrorMessage = ((PSQLException) nextException).getServerErrorMessage();
3605+
if (isPrimaryKeyError(serverErrorMessage, Config.getConfig(this).getBulkImportUsersTable())) {
3606+
throw new StorageTransactionLogicException(new io.supertokens.pluginInterface.bulkimport.exceptions.DuplicateUserIdException());
3607+
}
3608+
if (isForeignKeyConstraintError(serverErrorMessage, Config.getConfig(this).getBulkImportUsersTable(),
3609+
"app_id")) {
3610+
throw new TenantOrAppNotFoundException(appIdentifier);
3611+
}
36073612
}
3613+
36083614
}
36093615
}
36103616
return null;

0 commit comments

Comments
 (0)