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