Skip to content

Commit 084ee2d

Browse files
authored
Merge pull request #241 from supertokens/feat/bulk-import-test-fixes
fix: fixing tests by proper exception handling
2 parents 90750e1 + 3574f83 commit 084ee2d

File tree

1 file changed

+13
-8
lines changed
  • src/main/java/io/supertokens/storage/postgresql

1 file changed

+13
-8
lines changed

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

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3596,15 +3596,20 @@ 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+
SQLException nextException = batchUpdateException.getNextException();
3602+
if(nextException instanceof PSQLException){
3603+
ServerErrorMessage serverErrorMessage = ((PSQLException) nextException).getServerErrorMessage();
3604+
if (isPrimaryKeyError(serverErrorMessage, Config.getConfig(this).getBulkImportUsersTable())) {
3605+
throw new StorageTransactionLogicException(new io.supertokens.pluginInterface.bulkimport.exceptions.DuplicateUserIdException());
3606+
}
3607+
if (isForeignKeyConstraintError(serverErrorMessage, Config.getConfig(this).getBulkImportUsersTable(),
3608+
"app_id")) {
3609+
throw new TenantOrAppNotFoundException(appIdentifier);
3610+
}
36073611
}
3612+
36083613
}
36093614
}
36103615
return null;

0 commit comments

Comments
 (0)