I have the following code which executes spring DatabaseClient
insert logic:
suspend fun saveXXX(xxx: XXX): InsertStatus {
return try {
doSave(xxx)
InsertStatus.INSERTED
} catch (exception: DuplicateKeyException) {
val errDetails = (exception.cause as PostgresqlException).errorDetails
if (errDetails.code == "23505") {
val constraintName = errDetails.constraintName.get()
if (constraintName == "unique_1") {
return InsertStatus.DUPLICATE_1
} else if (constraintName == "unique_2") {
return InsertStatus.DUPLICATE_2
}
}
return InsertStatus.UNKNOWN_ERROR
}
}
private suspend fun doSave(xxx: XXX) {
databaseClient
.sql(
"""
SOME SQL
""".trimIndent(),
).bind(...)
.rowsUpdated()
.awaitSingle()
}
The problem that I face is during IntelliJ idea execution this code behaves as expected, so exception.cause
is a subtype of PostgresqlException
, but during gradle run with command ./gradlew clean build
the exception.cause
is wrapped around with another DuplicateKeyException
, so essentialy the exception should be DuplicateKeyException(PostgresqlException)
but effectively it is DuplicateKeyException(DuplicateKeyException(PostgresqlException))
. And once again, this only happens during gradle run.
What could be the cause of this?
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744702201a4588838.html
评论列表(0条)