fix: reduce attempts for downloading image, invert unreachable type check

This commit is contained in:
0x330a 2023-06-15 17:44:16 +10:00
parent 77ee554450
commit b5eaed3cbb
No known key found for this signature in database
GPG Key ID: 267811D6E6A2698C
2 changed files with 5 additions and 3 deletions

View File

@ -446,8 +446,8 @@ object OnionRequestAPI {
val payloadData = JsonUtil.toJson(payload).toByteArray()
return sendOnionRequest(Destination.Snode(snode), payloadData, version).recover { exception ->
val error = when (exception) {
is HTTP.HTTPRequestFailedException -> SnodeAPI.handleSnodeError(exception.statusCode, exception.json, snode, publicKey)
is HTTPRequestFailedAtDestinationException -> SnodeAPI.handleSnodeError(exception.statusCode, exception.json, snode, publicKey)
is HTTP.HTTPRequestFailedException -> SnodeAPI.handleSnodeError(exception.statusCode, exception.json, snode, publicKey)
else -> null
}
if (error != null) { throw error }

View File

@ -4,7 +4,9 @@ import okhttp3.HttpUrl
import org.session.libsession.messaging.file_server.FileServerApi
import org.session.libsignal.utilities.HTTP
import org.session.libsignal.utilities.Log
import java.io.*
import java.io.File
import java.io.FileOutputStream
import java.io.OutputStream
object DownloadUtilities {
@ -14,7 +16,7 @@ object DownloadUtilities {
@JvmStatic
fun downloadFile(destination: File, url: String) {
val outputStream = FileOutputStream(destination) // Throws
var remainingAttempts = 4
var remainingAttempts = 2
var exception: Exception? = null
while (remainingAttempts > 0) {
remainingAttempts -= 1