Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -417,8 +417,9 @@ object OnionRequestAPI {
// 404 is probably file server missing a file, don't rebuild path or mark a snode as bad here
Log.d("Loki","Request returned a non penalizing code ${exception.statusCode} with message: $message")
}
else if (destination is Destination.Server
&& (exception.statusCode == 500 || exception.statusCode == 504)) {
else if (destination is Destination.Server &&
(exception.statusCode in 500..504) &&
(exception is HTTPRequestFailedAtDestinationException || exception.body?.contains(destination.host) == true)) {
Log.d("Loki","Destination server error - Non path penalizing. Request returned code ${exception.statusCode} with message: $message")
} else if (message == "Loki Server error") {
Log.d("Loki", "message was $message")
Expand Down
19 changes: 14 additions & 5 deletions app/src/main/java/org/session/libsignal/utilities/HTTP.kt
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ object HTTP {

open class HTTPRequestFailedException(
val statusCode: Int,
val json: Map<*, *>?,
val json: Map<*, *>? = null,
val body: String? = null,
message: String = "HTTP request failed with status code $statusCode"
) : kotlin.Exception(message)
class HTTPNoNetworkException : HTTPRequestFailedException(0, null, "No network connection")
Expand Down Expand Up @@ -131,10 +132,10 @@ object HTTP {
else -> defaultConnection
}.newCall(request.build()).await().use { response ->
when (val statusCode = response.code) {
200 -> response.body!!.bytes()
in 200..299 -> response.body.bytes()
else -> {
Log.d("Loki", "${verb.rawValue} request to $url failed with status code: $statusCode.")
throw HTTPRequestFailedException(statusCode, null)
throw HTTPRequestFailedException(statusCode, body = response.body.string())
}
}
}
Expand All @@ -143,8 +144,16 @@ object HTTP {

if (!isConnectedToNetwork()) { throw HTTPNoNetworkException() }

// Override the actual error so that we can correctly catch failed requests in OnionRequestAPI
throw HTTPRequestFailedException(0, null, "HTTP request failed due to: ${exception.message}")
if (exception !is HTTPRequestFailedException) {

// Override the actual error so that we can correctly catch failed requests in OnionRequestAPI
throw HTTPRequestFailedException(
statusCode = 0,
message = "HTTP request failed due to: ${exception.message}"
)
} else {
throw exception
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import org.session.libsession.utilities.recipients.displayName
import org.session.libsignal.utilities.IdPrefix
import org.thoughtcrime.securesms.database.RecipientRepository
import org.thoughtcrime.securesms.pro.ProStatusManager
import org.thoughtcrime.securesms.ui.theme.classicDark3
import java.math.BigInteger
import java.security.MessageDigest
import java.util.Locale
Expand Down Expand Up @@ -101,7 +102,13 @@ class AvatarUtils @Inject constructor(
// custom image
val (remoteFile, customIcon, color) = when {
// use custom image if there is one
recipient.avatar != null -> Triple(recipient.avatar!!, null, defaultColor)
recipient.avatar != null -> Triple(
recipient.avatar!!,
// for communities, have an icon fallback in case the image errors out
if(recipient.isCommunityRecipient) R.drawable.session_logo else null,
// communities should always have a neutral fallback bg
if(recipient.isCommunityRecipient) classicDark3 else defaultColor
)

// communities without a custom image should use a default image
recipient.isCommunityRecipient -> Triple(null, R.drawable.session_logo, null)
Expand Down