Improve error handling on download failure

This commit is contained in:
Niels van Velzen
2026-08-11 15:55:07 +02:00
committed by Niels van Velzen
parent 697633cdf4
commit 9cd4b17f7e
2 changed files with 24 additions and 7 deletions
@@ -16,6 +16,7 @@ import org.jellyfin.sdk.api.client.extensions.imageApi
import org.jellyfin.sdk.api.client.extensions.libraryApi
import org.jellyfin.sdk.model.api.ImageFormat
import org.jellyfin.sdk.model.api.ImageType
import java.io.IOException
class DownloadQueue(
private val context: Context,
@@ -70,11 +71,15 @@ class DownloadQueue(
notificationProgressCallback.onEnd()
downloadDao.update(downloadWithFiles.download.copy(status = DownloadStatus.DOWNLOADED))
} catch (_: CancellationException) {
} catch (e: CancellationException) {
downloadDao.update(downloadWithFiles.download.copy(status = DownloadStatus.QUEUED))
} catch (error: Throwable) {
throw e
} catch (e: IOException) {
downloadDao.update(downloadWithFiles.download.copy(status = DownloadStatus.QUEUED))
throw e
} catch (e: Exception) {
downloadDao.update(downloadWithFiles.download.copy(status = DownloadStatus.ERROR))
throw error
throw e
}
}
@@ -111,6 +116,9 @@ class DownloadQueue(
status = DownloadStatus.DOWNLOADED,
),
)
} catch (e: IOException) {
downloadDao.updateFile(file.copy(status = DownloadStatus.QUEUED))
throw e
} catch (e: Exception) {
downloadDao.updateFile(file.copy(status = DownloadStatus.ERROR))
throw e
@@ -11,9 +11,11 @@ import androidx.work.OutOfQuotaPolicy
import androidx.work.WorkInfo
import androidx.work.WorkManager
import androidx.work.WorkerParameters
import kotlinx.coroutines.CancellationException
import org.jellyfin.mobile.app.AppPreferences
import org.koin.core.component.KoinComponent
import org.koin.core.component.inject
import java.io.IOException
class DownloadWorker(
context: Context,
@@ -57,11 +59,18 @@ class DownloadWorker(
override suspend fun doWork(): Result {
val canProcess = downloadQueue.prepare()
if (!canProcess) return Result.failure()
if (!canProcess) return Result.success()
setForeground(getForegroundInfo())
downloadQueue.process()
return Result.success()
return try {
downloadQueue.process()
Result.success()
} catch (e: CancellationException) {
throw e
} catch (_: IOException) {
Result.retry()
} catch (_: Exception) {
Result.failure()
}
}
}