Catch network errors during file downloading.

Fixes #1229
This commit is contained in:
onurays 2020-04-13 17:48:19 +03:00
parent eb50256af7
commit 7242cbda40
2 changed files with 4 additions and 1 deletions

View File

@ -25,6 +25,7 @@ Bugfix 🐛:
- Cross- Signing | After signin in new session, verification paper trail in DM is off (#1191) - Cross- Signing | After signin in new session, verification paper trail in DM is off (#1191)
- Failed to encrypt message in room (message stays in red), [thanks to pwr22] (#925) - Failed to encrypt message in room (message stays in red), [thanks to pwr22] (#925)
- Cross-Signing | web <-> riotX After QR code scan, gossiping fails (#1210) - Cross-Signing | web <-> riotX After QR code scan, gossiping fails (#1210)
- Fix crash when trying to download file without internet connection (#1229)
Translations 🗣: Translations 🗣:
- -

View File

@ -19,6 +19,7 @@ package im.vector.matrix.android.internal.session
import android.os.Environment import android.os.Environment
import arrow.core.Try import arrow.core.Try
import im.vector.matrix.android.api.MatrixCallback import im.vector.matrix.android.api.MatrixCallback
import im.vector.matrix.android.api.extensions.tryThis
import im.vector.matrix.android.api.session.content.ContentUrlResolver import im.vector.matrix.android.api.session.content.ContentUrlResolver
import im.vector.matrix.android.api.session.file.FileService import im.vector.matrix.android.api.session.file.FileService
import im.vector.matrix.android.api.util.Cancelable import im.vector.matrix.android.api.util.Cancelable
@ -77,9 +78,10 @@ internal class DefaultFileService @Inject constructor(
.url(resolvedUrl) .url(resolvedUrl)
.build() .build()
val response = okHttpClient.newCall(request).execute() val response = tryThis { okHttpClient.newCall(request).execute() } ?: return@flatMap Try.Failure(IOException())
var inputStream = response.body?.byteStream() var inputStream = response.body?.byteStream()
Timber.v("Response size ${response.body?.contentLength()} - Stream available: ${inputStream?.available()}") Timber.v("Response size ${response.body?.contentLength()} - Stream available: ${inputStream?.available()}")
if (!response.isSuccessful || inputStream == null) { if (!response.isSuccessful || inputStream == null) {
return@flatMap Try.Failure(IOException()) return@flatMap Try.Failure(IOException())
} }