From 2738c64815dfec4c3962f868b3be264df83eeb9a Mon Sep 17 00:00:00 2001 From: Noel Date: Fri, 18 Mar 2022 09:09:04 -0700 Subject: [PATCH] chore: fix some null errors in /v2/sponsors/{login} --- build.gradle.kts | 2 +- .../routing/endpoints/api/v2/SponsorV2Endpoints.kt | 14 ++++++-------- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 67f8a89a..660d8221 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -54,7 +54,7 @@ plugins { apply(plugin = "kotlinx-atomicfu") val JAVA_VERSION = JavaVersion.VERSION_17 -val VERSION = Version(4, 0, 3, 0, ReleaseType.None) +val VERSION = Version(4, 0, 4, 0, ReleaseType.None) val commitHash by lazy { val cmd = "git rev-parse --short HEAD".split("\\s".toRegex()) diff --git a/src/main/kotlin/gay/floof/hana/routing/endpoints/api/v2/SponsorV2Endpoints.kt b/src/main/kotlin/gay/floof/hana/routing/endpoints/api/v2/SponsorV2Endpoints.kt index 741a8a13..62e8be3a 100644 --- a/src/main/kotlin/gay/floof/hana/routing/endpoints/api/v2/SponsorV2Endpoints.kt +++ b/src/main/kotlin/gay/floof/hana/routing/endpoints/api/v2/SponsorV2Endpoints.kt @@ -195,8 +195,6 @@ class FetchSponsorV2Endpoint(private val config: HanaConfig, private val httpCli val sponsoring = data["data"]!!.jsonObject["user"]!!.jsonObject["sponsorshipsAsSponsor"]!!.jsonObject val sponsors = data["data"]!!.jsonObject["user"]!!.jsonObject["sponsorshipsAsMaintainer"]!!.jsonObject - println(sponsoring) - call.respond( HttpStatusCode.OK, buildJsonObject { @@ -296,9 +294,9 @@ class FetchSponsorV2Endpoint(private val config: HanaConfig, private val httpCli put( "price", if (pricing == "Dollars") { - tier["monthlyPriceInDollars"]!! + tier["monthlyPriceInDollars"] ?: JsonNull } else { - tier["monthlyPriceInCents"]!! + tier["monthlyPriceInCents"] ?: JsonNull } ) } @@ -306,8 +304,8 @@ class FetchSponsorV2Endpoint(private val config: HanaConfig, private val httpCli val sponsorEntity = obj["sponsorEntity"]!!.jsonObject - put("followers", sponsorEntity["following"]!!) - put("followers", sponsorEntity["followers"]!!) + put("followers", sponsorEntity["following"]!!.jsonObject["totalCount"]!!.jsonPrimitive.int) + put("followers", sponsorEntity["followers"]!!.jsonObject["totalCount"]!!.jsonPrimitive.int) val status = try { sponsorEntity["status"]?.jsonObject @@ -319,8 +317,8 @@ class FetchSponsorV2Endpoint(private val config: HanaConfig, private val httpCli put( "status", buildJsonObject { - put("emoji", status["emojiHTML"]!!) - put("message", status["message"]!!) + put("emoji", status["emojiHTML"]?.jsonPrimitive?.contentOrNull) + put("message", status["message"]?.jsonPrimitive?.contentOrNull) put("expires_at", status["expiresAt"]?.jsonPrimitive?.content) } )