From d81c6ffda7b3a49d975de3dc051e6ec5e918d080 Mon Sep 17 00:00:00 2001 From: Bruno Deanoz Date: Fri, 19 Jun 2026 09:06:55 +0200 Subject: [PATCH] fix: make KaizenApi exceptionally robust against malformed JSON or parsing failures --- .../main/java/dev/kaizen/app/net/KaizenApi.kt | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/dev/kaizen/app/net/KaizenApi.kt b/app/src/main/java/dev/kaizen/app/net/KaizenApi.kt index b70894e..1aa466f 100644 --- a/app/src/main/java/dev/kaizen/app/net/KaizenApi.kt +++ b/app/src/main/java/dev/kaizen/app/net/KaizenApi.kt @@ -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(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(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(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(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(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 } }