Prevent crashes when failing to decode event json
This commit is contained in:
parent
92495c06c4
commit
68409a7484
2 changed files with 10 additions and 1 deletions
|
@ -39,7 +39,11 @@ internal data class Event(
|
|||
val props: String?
|
||||
) {
|
||||
companion object {
|
||||
fun fromJson(json: String): Event = Json.decodeFromString(json)
|
||||
fun fromJson(json: String): Event? = try {
|
||||
Json.decodeFromString(json)
|
||||
} catch (ignored: Exception) {
|
||||
null
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -95,6 +95,11 @@ internal class NetworkFirstPlausibleClient(
|
|||
config.eventDir.mkdirs()
|
||||
config.eventDir.listFiles()?.forEach {
|
||||
val event = Event.fromJson(it.readText())
|
||||
if (event == null) {
|
||||
Timber.tag("Plausible").e("Failed to decode event JSON, discarding")
|
||||
it.delete()
|
||||
return@forEach
|
||||
}
|
||||
try {
|
||||
postEvent(event)
|
||||
} catch (e: IOException) {
|
||||
|
|
Loading…
Reference in a new issue