From 9dee1efa43b99c0eabd5a740c090bd8666afdd0e Mon Sep 17 00:00:00 2001 From: TheSaminator Date: Sun, 6 Feb 2022 18:10:56 -0500 Subject: [PATCH] Attempt to find exception????? --- src/jvmMain/kotlin/starshipfights/auth/providers.kt | 6 +++--- src/jvmMain/kotlin/starshipfights/data/data_documents.kt | 8 +++++++- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/jvmMain/kotlin/starshipfights/auth/providers.kt b/src/jvmMain/kotlin/starshipfights/auth/providers.kt index ac24f2c..abd3eb7 100644 --- a/src/jvmMain/kotlin/starshipfights/auth/providers.kt +++ b/src/jvmMain/kotlin/starshipfights/auth/providers.kt @@ -14,6 +14,7 @@ import io.ktor.util.* import kotlinx.coroutines.coroutineScope import kotlinx.coroutines.launch import kotlinx.html.* +import org.litote.kmongo.eq import starshipfights.CurrentConfiguration import starshipfights.data.Id import starshipfights.data.admiralty.Admiral @@ -195,9 +196,8 @@ object TestAuthProvider : AuthProvider { val userAgent = request.userAgent() if (userAgent != null && credentials.name.isValidUsername() && credentials.password == TEST_PASSWORD) { sfLogger.info("Attempting to find user ${credentials.name}") - val user = //User.locate(User::username eq credentials.name) - //?: User(username = credentials.name).also { - User(username = credentials.name).also { + val user = User.locate(User::username eq credentials.name) + ?: User(username = credentials.name).also { sfLogger.info("Attempting to add user with name ${credentials.name}") User.put(it) } diff --git a/src/jvmMain/kotlin/starshipfights/data/data_documents.kt b/src/jvmMain/kotlin/starshipfights/data/data_documents.kt index 2be671b..13f0de0 100644 --- a/src/jvmMain/kotlin/starshipfights/data/data_documents.kt +++ b/src/jvmMain/kotlin/starshipfights/data/data_documents.kt @@ -10,6 +10,7 @@ import org.litote.kmongo.coroutine.coroutine import org.litote.kmongo.serialization.IdController import org.slf4j.Logger import org.slf4j.LoggerFactory +import starshipfights.sfLogger import kotlin.coroutines.CoroutineContext import kotlin.reflect.KClass import kotlin.reflect.KProperty1 @@ -111,7 +112,12 @@ private class DocumentTableImpl>(val kclass: KClass, priv } override suspend fun locate(bson: Bson): T? { - return collection().findOne(bson) + try { + return collection().findOne(bson) + } catch (ex: Exception) { + sfLogger.error("Got exception from table ${kclass.simpleName}", ex) + throw ex + } } override suspend fun update(where: Bson, set: Bson) { -- 2.25.1