fix: crash on comments api connection failure
This commit is contained in:
parent
6c14a2eccf
commit
4628282715
2 changed files with 8 additions and 2 deletions
|
@ -17,6 +17,7 @@ import kotlinx.serialization.encoding.Decoder
|
||||||
import kotlinx.serialization.encoding.Encoder
|
import kotlinx.serialization.encoding.Encoder
|
||||||
import kotlinx.serialization.json.Json
|
import kotlinx.serialization.json.Json
|
||||||
import okhttp3.FormBody
|
import okhttp3.FormBody
|
||||||
|
import okio.IOException
|
||||||
import uy.kohesive.injekt.Injekt
|
import uy.kohesive.injekt.Injekt
|
||||||
import uy.kohesive.injekt.api.get
|
import uy.kohesive.injekt.api.get
|
||||||
|
|
||||||
|
@ -159,7 +160,12 @@ object CommentsAPI {
|
||||||
.add("token", token)
|
.add("token", token)
|
||||||
.build()
|
.build()
|
||||||
val request = requestBuilder()
|
val request = requestBuilder()
|
||||||
val json = request.post(url, requestBody = body)
|
val json = try {
|
||||||
|
request.post(url, requestBody = body)
|
||||||
|
} catch (e: IOException) {
|
||||||
|
snackString("Failed to login to comments API")
|
||||||
|
return
|
||||||
|
}
|
||||||
if (!json.text.startsWith("{")) return
|
if (!json.text.startsWith("{")) return
|
||||||
val parsed = try {
|
val parsed = try {
|
||||||
Json.decodeFromString<AuthResponse>(json.text)
|
Json.decodeFromString<AuthResponse>(json.text)
|
||||||
|
|
|
@ -34,8 +34,8 @@ class NetworkHelper(
|
||||||
maxSize = 5L * 1024 * 1024, // 5 MiB
|
maxSize = 5L * 1024 * 1024, // 5 MiB
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
.addInterceptor(BrotliInterceptor)
|
|
||||||
.addInterceptor(UncaughtExceptionInterceptor())
|
.addInterceptor(UncaughtExceptionInterceptor())
|
||||||
|
.addInterceptor(BrotliInterceptor)
|
||||||
.addInterceptor(UserAgentInterceptor(::defaultUserAgentProvider))
|
.addInterceptor(UserAgentInterceptor(::defaultUserAgentProvider))
|
||||||
|
|
||||||
if (PrefManager.getVal(PrefName.VerboseLogging)) {
|
if (PrefManager.getVal(PrefName.VerboseLogging)) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue