summaryrefslogtreecommitdiff
path: root/util/src/main/kotlin/DB.kt
diff options
context:
space:
mode:
authorAntoine A <>2023-11-21 04:18:01 +0000
committerAntoine A <>2023-11-21 04:18:01 +0000
commit9e9cfb04e56f23b9dac2a782fd8951151fd1e6ad (patch)
tree2e32ce667c6e235824ab125e5c5865b3d6efc03d /util/src/main/kotlin/DB.kt
parent0692f2f29d6106deca9097e83aa4e3f98017a881 (diff)
downloadlibeufin-9e9cfb04e56f23b9dac2a782fd8951151fd1e6ad.tar.gz
libeufin-9e9cfb04e56f23b9dac2a782fd8951151fd1e6ad.tar.bz2
libeufin-9e9cfb04e56f23b9dac2a782fd8951151fd1e6ad.zip
Catch and format SQLException
Diffstat (limited to 'util/src/main/kotlin/DB.kt')
-rw-r--r--util/src/main/kotlin/DB.kt5
1 files changed, 3 insertions, 2 deletions
diff --git a/util/src/main/kotlin/DB.kt b/util/src/main/kotlin/DB.kt
index ebc7d7e2..1a7571df 100644
--- a/util/src/main/kotlin/DB.kt
+++ b/util/src/main/kotlin/DB.kt
@@ -25,6 +25,7 @@ import kotlinx.coroutines.coroutineScope
import net.taler.wallet.crypto.Base32Crockford
import org.postgresql.ds.PGSimpleDataSource
import org.postgresql.jdbc.PgConnection
+import org.postgresql.util.PSQLState
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import java.io.File
@@ -171,7 +172,7 @@ fun PreparedStatement.executeUpdateViolation(): Boolean {
executeUpdateCheck()
} catch (e: SQLException) {
logger.error(e.message)
- if (e.sqlState == "23505") return false // unique_violation
+ if (e.sqlState == PSQLState.UNIQUE_VIOLATION.state) return false
throw e // rethrowing, not to hide other types of errors.
}
}
@@ -184,7 +185,7 @@ fun PreparedStatement.executeProcedureViolation(): Boolean {
true
} catch (e: SQLException) {
connection.rollback(savepoint);
- if (e.sqlState == "23505") return false // unique_violation
+ if (e.sqlState == PSQLState.UNIQUE_VIOLATION.state) return false
throw e // rethrowing, not to hide other types of errors.
}
}