Catch JSONFeedAdapter exceptions

This commit is contained in:
Shinokuni 2020-09-20 18:48:43 +02:00
parent 694ff6331e
commit cb41f3c7ac
1 changed files with 18 additions and 13 deletions

View File

@ -1,5 +1,6 @@
package com.readrops.api.localfeed.json package com.readrops.api.localfeed.json
import com.readrops.api.utils.ParseException
import com.readrops.api.utils.nextNullableString import com.readrops.api.utils.nextNullableString
import com.readrops.db.entities.Feed import com.readrops.db.entities.Feed
import com.squareup.moshi.FromJson import com.squareup.moshi.FromJson
@ -13,23 +14,27 @@ class JSONFeedAdapter {
@FromJson @FromJson
fun fromJson(reader: JsonReader): Feed { fun fromJson(reader: JsonReader): Feed {
val feed = Feed() try {
reader.beginObject() val feed = Feed()
reader.beginObject()
while (reader.hasNext()) { while (reader.hasNext()) {
with(feed) { with(feed) {
when (reader.selectName(names)) { when (reader.selectName(names)) {
0 -> name = reader.nextString() 0 -> name = reader.nextString()
1 -> siteUrl = reader.nextNullableString() 1 -> siteUrl = reader.nextNullableString()
2 -> url = reader.nextNullableString() 2 -> url = reader.nextNullableString()
3 -> description = reader.nextNullableString() 3 -> description = reader.nextNullableString()
else -> reader.skipValue() else -> reader.skipValue()
}
} }
} }
}
reader.endObject() reader.endObject()
return feed return feed
} catch (e: Exception) {
throw ParseException(e.message)
}
} }
companion object { companion object {