fix: make KaizenApi exceptionally robust against malformed JSON or parsing failures

This commit is contained in:
Bruno Deanoz 2026-06-19 09:06:55 +02:00
parent 7399c73e6a
commit d81c6ffda7

View file

@ -34,7 +34,7 @@ import java.util.concurrent.TimeUnit
@Serializable @Serializable
data class KaizenModel( data class KaizenModel(
val id: String, val id: String,
val name: String, val name: String? = null,
val provider: String? = null, val provider: String? = null,
) )
@ -137,7 +137,7 @@ object KaizenApi {
if (!resp.isSuccessful) return@use null if (!resp.isSuccessful) return@use null
json.decodeFromString<MeResponse>(resp.body!!.string()).defaultModel json.decodeFromString<MeResponse>(resp.body!!.string()).defaultModel
} }
} catch (e: IOException) { } catch (e: Exception) {
null null
} }
} }
@ -154,7 +154,7 @@ object KaizenApi {
if (!resp.isSuccessful) return@use emptyList() if (!resp.isSuccessful) return@use emptyList()
json.decodeFromString<ModelsResponse>(resp.body!!.string()).models json.decodeFromString<ModelsResponse>(resp.body!!.string()).models
} }
} catch (e: IOException) { } catch (e: Exception) {
emptyList() emptyList()
} }
} }
@ -171,7 +171,7 @@ object KaizenApi {
if (!resp.isSuccessful) return@use emptyList() if (!resp.isSuccessful) return@use emptyList()
json.decodeFromString<ConversationsResponse>(resp.body!!.string()).conversations json.decodeFromString<ConversationsResponse>(resp.body!!.string()).conversations
} }
} catch (e: IOException) { } catch (e: Exception) {
emptyList() emptyList()
} }
} }
@ -190,7 +190,7 @@ object KaizenApi {
if (!resp.isSuccessful) return@use null if (!resp.isSuccessful) return@use null
json.decodeFromString<CreatedConversation>(resp.body!!.string()).id json.decodeFromString<CreatedConversation>(resp.body!!.string()).id
} }
} catch (e: IOException) { } catch (e: Exception) {
null null
} }
} }
@ -207,7 +207,7 @@ object KaizenApi {
if (!resp.isSuccessful) return@use emptyList() if (!resp.isSuccessful) return@use emptyList()
json.decodeFromString<ConversationDetail>(resp.body!!.string()).messages json.decodeFromString<ConversationDetail>(resp.body!!.string()).messages
} }
} catch (e: IOException) { } catch (e: Exception) {
emptyList() emptyList()
} }
} }
@ -223,7 +223,7 @@ object KaizenApi {
.build() .build()
try { try {
client.newCall(req).execute().use { resp -> resp.isSuccessful } client.newCall(req).execute().use { resp -> resp.isSuccessful }
} catch (e: IOException) { } catch (e: Exception) {
false false
} }
} }
@ -238,7 +238,7 @@ object KaizenApi {
.build() .build()
try { try {
client.newCall(req).execute().use { } client.newCall(req).execute().use { }
} catch (e: IOException) { } catch (e: Exception) {
// best-effort: a missing title is cosmetic // best-effort: a missing title is cosmetic
} }
} }