Skip to content

Commit

Permalink
fix: crash on comments api connection failure
Browse files Browse the repository at this point in the history
  • Loading branch information
rebelonion committed Feb 23, 2024
1 parent 6c14a2e commit 4628282
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import kotlinx.serialization.encoding.Decoder
import kotlinx.serialization.encoding.Encoder
import kotlinx.serialization.json.Json
import okhttp3.FormBody
import okio.IOException
import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get

Expand Down Expand Up @@ -159,7 +160,12 @@ object CommentsAPI {
.add("token", token)
.build()
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
val parsed = try {
Json.decodeFromString<AuthResponse>(json.text)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ class NetworkHelper(
maxSize = 5L * 1024 * 1024, // 5 MiB
),
)
.addInterceptor(BrotliInterceptor)
.addInterceptor(UncaughtExceptionInterceptor())
.addInterceptor(BrotliInterceptor)
.addInterceptor(UserAgentInterceptor(::defaultUserAgentProvider))

if (PrefManager.getVal(PrefName.VerboseLogging)) {
Expand Down

0 comments on commit 4628282

Please sign in to comment.