diff options
author | MS <ms@taler.net> | 2021-02-26 11:06:27 +0100 |
---|---|---|
committer | MS <ms@taler.net> | 2021-02-26 11:06:27 +0100 |
commit | 3ade91b4426c58703c314d6875d07704e72ec4fe (patch) | |
tree | 7968c58365b1ebd6165390a573fbcbfab9c29217 /nexus | |
parent | 3c00d5f26fd469ef91e58b85b6c143fd05bb395a (diff) | |
download | libeufin-3ade91b4426c58703c314d6875d07704e72ec4fe.tar.gz libeufin-3ade91b4426c58703c314d6875d07704e72ec4fe.tar.bz2 libeufin-3ade91b4426c58703c314d6875d07704e72ec4fe.zip |
resolving #6770
Diffstat (limited to 'nexus')
-rw-r--r-- | nexus/src/main/kotlin/tech/libeufin/nexus/DB.kt | 3 | ||||
-rw-r--r-- | nexus/src/main/kotlin/tech/libeufin/nexus/server/NexusServer.kt | 21 |
2 files changed, 18 insertions, 6 deletions
diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/DB.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/DB.kt index 37b6e28d..75c5f880 100644 --- a/nexus/src/main/kotlin/tech/libeufin/nexus/DB.kt +++ b/nexus/src/main/kotlin/tech/libeufin/nexus/DB.kt @@ -339,6 +339,9 @@ object FacadesTable : LongIdTable() { val facadeName = text("facadeName") val type = text("type") val creator = reference("creator", NexusUsersTable) + init { + uniqueIndex(facadeName) + } } class FacadeEntity(id: EntityID<Long>) : LongEntity(id) { diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/server/NexusServer.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/server/NexusServer.kt index a679d28e..90c6f813 100644 --- a/nexus/src/main/kotlin/tech/libeufin/nexus/server/NexusServer.kt +++ b/nexus/src/main/kotlin/tech/libeufin/nexus/server/NexusServer.kt @@ -42,6 +42,7 @@ import io.ktor.server.netty.* import io.ktor.util.* import io.ktor.util.pipeline.* import io.ktor.utils.io.* +import org.jetbrains.exposed.exceptions.ExposedSQLException import org.jetbrains.exposed.sql.and import org.jetbrains.exposed.sql.transactions.transaction import org.slf4j.event.Level @@ -956,13 +957,21 @@ fun serverMain(dbName: String, host: String, port: Int) { HttpStatusCode.NotImplemented, "Facade type '${body.type}' is not implemented" ) - val newFacade = transaction { - val user = authenticateRequest(call.request) - FacadeEntity.new { - facadeName = body.name - type = body.type - creator = user + val newFacade = try { + transaction { + val user = authenticateRequest(call.request) + FacadeEntity.new { + facadeName = body.name + type = body.type + creator = user + } } + } catch (e: ExposedSQLException) { + logger.error("Could not persist facade name/type/creator: $e") + throw NexusError( + HttpStatusCode.BadRequest, + "Server could not persist data, possibly due to unavailable facade name" + ) } transaction { TalerFacadeStateEntity.new { |