diff --git a/app/src/main/java/io/legado/app/help/storage/OldRule.kt b/app/src/main/java/io/legado/app/help/storage/OldRule.kt index f5919eb2c..b69b35526 100644 --- a/app/src/main/java/io/legado/app/help/storage/OldRule.kt +++ b/app/src/main/java/io/legado/app/help/storage/OldRule.kt @@ -20,7 +20,7 @@ object OldRule { } catch (e: Exception) { null } - runCatching { + try { if (sourceAny?.ruleToc == null) { source.apply { val jsonItem = jsonPath.parse(json.trim()) @@ -125,6 +125,8 @@ object OldRule { GSON.fromJsonObject(GSON.toJson(sourceAny.ruleContent)) } } + } catch (e: Exception) { + e.printStackTrace() } return source } diff --git a/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceViewModel.kt b/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceViewModel.kt index 5077a71cf..c6dc63c8e 100644 --- a/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceViewModel.kt @@ -233,6 +233,7 @@ class BookSourceViewModel(application: Application) : BaseViewModel(application) else -> "格式不对" } }.onError { + it.printStackTrace() finally(it.localizedMessage ?: "") }.onSuccess { finally(it) @@ -240,7 +241,11 @@ class BookSourceViewModel(application: Application) : BaseViewModel(application) } private fun importSourceUrl(url: String): Int { - HttpHelper.simpleGet(url, "UTF-8")?.let { body -> + HttpHelper.simpleGet(url, "UTF-8").let { body -> + if (body == null) { + toast("访问网站失败") + return 0 + } val bookSources = mutableListOf() val items: List> = jsonPath.parse(body).read("$") for (item in items) { @@ -252,6 +257,5 @@ class BookSourceViewModel(application: Application) : BaseViewModel(application) App.db.bookSourceDao().insert(*bookSources.toTypedArray()) return bookSources.size } - return 0 } } \ No newline at end of file