diff --git a/api/src/main/kotlin/dev/msfjarvis/claw/api/converters/CSRFTokenConverter.kt b/api/src/main/kotlin/dev/msfjarvis/claw/api/converters/CSRFTokenConverter.kt index 18bf8695..05c32b92 100644 --- a/api/src/main/kotlin/dev/msfjarvis/claw/api/converters/CSRFTokenConverter.kt +++ b/api/src/main/kotlin/dev/msfjarvis/claw/api/converters/CSRFTokenConverter.kt @@ -1,5 +1,5 @@ /* - * Copyright © 2023 Harsh Shandilya. + * Copyright © 2023-2024 Harsh Shandilya. * Use of this source code is governed by an MIT-style * license that can be found in the LICENSE file or at * https://opensource.org/licenses/MIT. @@ -19,8 +19,9 @@ object CSRFTokenConverter : Converter { val token = Jsoup.parse(value.string(), LobstersApi.BASE_URL) .select("meta[name=\"csrf-token\"]") - .first()!! - .attr("content") + .firstOrNull() + ?.attr("content") + .orEmpty() return CSRFToken(token) } diff --git a/api/src/test/kotlin/dev/msfjarvis/claw/util/TestUtils.kt b/api/src/test/kotlin/dev/msfjarvis/claw/util/TestUtils.kt index 00c5346b..6cad5c02 100644 --- a/api/src/test/kotlin/dev/msfjarvis/claw/util/TestUtils.kt +++ b/api/src/test/kotlin/dev/msfjarvis/claw/util/TestUtils.kt @@ -1,5 +1,5 @@ /* - * Copyright © 2021-2023 Harsh Shandilya. + * Copyright © 2021-2024 Harsh Shandilya. * Use of this source code is governed by an MIT-style * license that can be found in the LICENSE file or at * https://opensource.org/licenses/MIT. @@ -15,7 +15,9 @@ import kotlin.contracts.contract object TestUtils { fun getResource(path: String): String { // Load the JSON response - val uri = javaClass.classLoader!!.getResource(path) + val uri = + requireNotNull(javaClass.classLoader) { "if this is null something has gone very wrong" } + .getResource(path) val file = File(uri.path) return String(file.readBytes()) }