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?
|
val props: String?
|
||||||
) {
|
) {
|
||||||
companion object {
|
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.mkdirs()
|
||||||
config.eventDir.listFiles()?.forEach {
|
config.eventDir.listFiles()?.forEach {
|
||||||
val event = Event.fromJson(it.readText())
|
val event = Event.fromJson(it.readText())
|
||||||
|
if (event == null) {
|
||||||
|
Timber.tag("Plausible").e("Failed to decode event JSON, discarding")
|
||||||
|
it.delete()
|
||||||
|
return@forEach
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
postEvent(event)
|
postEvent(event)
|
||||||
} catch (e: IOException) {
|
} catch (e: IOException) {
|
||||||
|
|
Loading…
Reference in a new issue