Horis 2 лет назад
Родитель
Сommit
0c91c591b7

+ 4 - 3
app/src/main/java/io/legado/app/help/update/AppReleaseInfo.kt

@@ -1,6 +1,7 @@
 package io.legado.app.help.update
 package io.legado.app.help.update
 
 
 import com.google.gson.annotations.SerializedName
 import com.google.gson.annotations.SerializedName
+import io.legado.app.exception.NoStackTraceException
 import java.time.Instant
 import java.time.Instant
 
 
 data class AppReleaseInfo(
 data class AppReleaseInfo(
@@ -33,10 +34,10 @@ data class GithubRelease(
     val isPreRelease: Boolean,
     val isPreRelease: Boolean,
 ) {
 ) {
     fun gitReleaseToAppReleaseInfo(): List<AppReleaseInfo> {
     fun gitReleaseToAppReleaseInfo(): List<AppReleaseInfo> {
+        assets ?: throw NoStackTraceException("获取新版本出错")
         return assets
         return assets
-            ?.filter { it.isValid }
-            ?.map { it.assetToAppReleaseInfo(isPreRelease, body) }
-            .orEmpty()
+            .filter { it.isValid }
+            .map { it.assetToAppReleaseInfo(isPreRelease, body) }
     }
     }
 }
 }
 
 

+ 8 - 3
app/src/main/java/io/legado/app/help/update/AppUpdateGitHub.kt

@@ -5,8 +5,9 @@ import io.legado.app.constant.AppConst
 import io.legado.app.exception.NoStackTraceException
 import io.legado.app.exception.NoStackTraceException
 import io.legado.app.help.config.AppConfig
 import io.legado.app.help.config.AppConfig
 import io.legado.app.help.coroutine.Coroutine
 import io.legado.app.help.coroutine.Coroutine
-import io.legado.app.help.http.newCallStrResponse
+import io.legado.app.help.http.newCallResponse
 import io.legado.app.help.http.okHttpClient
 import io.legado.app.help.http.okHttpClient
+import io.legado.app.help.http.text
 import io.legado.app.utils.GSON
 import io.legado.app.utils.GSON
 import io.legado.app.utils.fromJsonObject
 import io.legado.app.utils.fromJsonObject
 import kotlinx.coroutines.CoroutineScope
 import kotlinx.coroutines.CoroutineScope
@@ -29,9 +30,13 @@ object AppUpdateGitHub : AppUpdate.AppUpdateInterface {
         } else {
         } else {
             "https://api.github.com/repos/gedoor/legado/releases/latest"
             "https://api.github.com/repos/gedoor/legado/releases/latest"
         }
         }
-        val body = okHttpClient.newCallStrResponse {
+        val res = okHttpClient.newCallResponse {
             url(lastReleaseUrl)
             url(lastReleaseUrl)
-        }.body
+        }
+        if (!res.isSuccessful) {
+            throw NoStackTraceException("获取新版本出错(${res.code})")
+        }
+        val body = res.body?.text()
         if (body.isNullOrBlank()) {
         if (body.isNullOrBlank()) {
             throw NoStackTraceException("获取新版本出错")
             throw NoStackTraceException("获取新版本出错")
         }
         }