mirror of
https://github.com/oxen-io/session-android.git
synced 2024-11-23 18:15:22 +00:00
Cleaned up some of the error logging
This commit is contained in:
parent
afa42daab1
commit
0ed5c5825d
@ -47,6 +47,7 @@ import org.session.libsession.utilities.Util;
|
|||||||
import org.session.libsession.utilities.WindowDebouncer;
|
import org.session.libsession.utilities.WindowDebouncer;
|
||||||
import org.session.libsession.utilities.dynamiclanguage.DynamicLanguageContextWrapper;
|
import org.session.libsession.utilities.dynamiclanguage.DynamicLanguageContextWrapper;
|
||||||
import org.session.libsession.utilities.dynamiclanguage.LocaleParser;
|
import org.session.libsession.utilities.dynamiclanguage.LocaleParser;
|
||||||
|
import org.session.libsignal.utilities.HTTP;
|
||||||
import org.session.libsignal.utilities.JsonUtil;
|
import org.session.libsignal.utilities.JsonUtil;
|
||||||
import org.session.libsignal.utilities.Log;
|
import org.session.libsignal.utilities.Log;
|
||||||
import org.session.libsignal.utilities.ThreadUtils;
|
import org.session.libsignal.utilities.ThreadUtils;
|
||||||
@ -67,6 +68,7 @@ import org.thoughtcrime.securesms.groups.OpenGroupMigrator;
|
|||||||
import org.thoughtcrime.securesms.home.HomeActivity;
|
import org.thoughtcrime.securesms.home.HomeActivity;
|
||||||
import org.thoughtcrime.securesms.jobmanager.JobManager;
|
import org.thoughtcrime.securesms.jobmanager.JobManager;
|
||||||
import org.thoughtcrime.securesms.jobmanager.impl.JsonDataSerializer;
|
import org.thoughtcrime.securesms.jobmanager.impl.JsonDataSerializer;
|
||||||
|
import org.thoughtcrime.securesms.jobmanager.impl.NetworkConstraint;
|
||||||
import org.thoughtcrime.securesms.jobs.FastJobStorage;
|
import org.thoughtcrime.securesms.jobs.FastJobStorage;
|
||||||
import org.thoughtcrime.securesms.jobs.JobManagerFactories;
|
import org.thoughtcrime.securesms.jobs.JobManagerFactories;
|
||||||
import org.thoughtcrime.securesms.logging.AndroidLogger;
|
import org.thoughtcrime.securesms.logging.AndroidLogger;
|
||||||
@ -237,6 +239,9 @@ public class ApplicationContext extends Application implements DefaultLifecycleO
|
|||||||
resubmitProfilePictureIfNeeded();
|
resubmitProfilePictureIfNeeded();
|
||||||
loadEmojiSearchIndexIfNeeded();
|
loadEmojiSearchIndexIfNeeded();
|
||||||
EmojiSource.refresh();
|
EmojiSource.refresh();
|
||||||
|
|
||||||
|
NetworkConstraint networkConstraint = new NetworkConstraint.Factory(this).create();
|
||||||
|
HTTP.INSTANCE.setConnectedToNetwork(networkConstraint::isMet);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -77,7 +77,11 @@ object FileServerApi {
|
|||||||
OnionRequestAPI.sendOnionRequest(requestBuilder.build(), server, serverPublicKey).map {
|
OnionRequestAPI.sendOnionRequest(requestBuilder.build(), server, serverPublicKey).map {
|
||||||
it.body ?: throw Error.ParsingFailed
|
it.body ?: throw Error.ParsingFailed
|
||||||
}.fail { e ->
|
}.fail { e ->
|
||||||
Log.e("Loki", "File server request failed.", e)
|
when (e) {
|
||||||
|
// No need for the stack trace for HTTP errors
|
||||||
|
is HTTP.HTTPRequestFailedException -> Log.e("Loki", "File server request failed due to error: ${e.message}")
|
||||||
|
else -> Log.e("Loki", "File server request failed", e)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Promise.ofFail(IllegalStateException("It's currently not allowed to send non onion routed requests."))
|
Promise.ofFail(IllegalStateException("It's currently not allowed to send non onion routed requests."))
|
||||||
|
@ -94,13 +94,25 @@ class BatchMessageReceiveJob(
|
|||||||
threadMap[threadID]!! += parsedParams
|
threadMap[threadID]!! += parsedParams
|
||||||
}
|
}
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
Log.e(TAG, "Couldn't receive message.", e)
|
when (e) {
|
||||||
if (e is MessageReceiver.Error && !e.isRetryable) {
|
is MessageReceiver.Error.DuplicateMessage, MessageReceiver.Error.SelfSend -> {
|
||||||
Log.e(TAG, "Message failed permanently",e)
|
Log.i(TAG, "Couldn't receive message, failed with error: ${e.message}")
|
||||||
} else {
|
|
||||||
Log.e(TAG, "Message failed",e)
|
|
||||||
failures += messageParameters
|
failures += messageParameters
|
||||||
}
|
}
|
||||||
|
is MessageReceiver.Error -> {
|
||||||
|
if (!e.isRetryable) {
|
||||||
|
Log.e(TAG, "Couldn't receive message, failed permanently", e)
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Log.e(TAG, "Couldn't receive message, failed", e)
|
||||||
|
failures += messageParameters
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else -> {
|
||||||
|
Log.e(TAG, "Couldn't receive message, failed", e)
|
||||||
|
failures += messageParameters
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,6 +11,7 @@ import org.session.libsession.messaging.messages.visible.VisibleMessage
|
|||||||
import org.session.libsession.messaging.sending_receiving.MessageSender
|
import org.session.libsession.messaging.sending_receiving.MessageSender
|
||||||
import org.session.libsession.messaging.utilities.Data
|
import org.session.libsession.messaging.utilities.Data
|
||||||
import org.session.libsession.snode.OnionRequestAPI
|
import org.session.libsession.snode.OnionRequestAPI
|
||||||
|
import org.session.libsignal.utilities.HTTP
|
||||||
import org.session.libsignal.utilities.Log
|
import org.session.libsignal.utilities.Log
|
||||||
|
|
||||||
class MessageSendJob(val message: Message, val destination: Destination) : Job {
|
class MessageSendJob(val message: Message, val destination: Destination) : Job {
|
||||||
@ -67,14 +68,25 @@ class MessageSendJob(val message: Message, val destination: Destination) : Job {
|
|||||||
val promise = MessageSender.send(this.message, this.destination).success {
|
val promise = MessageSender.send(this.message, this.destination).success {
|
||||||
this.handleSuccess()
|
this.handleSuccess()
|
||||||
}.fail { exception ->
|
}.fail { exception ->
|
||||||
Log.e(TAG, "Couldn't send message due to error: $exception.")
|
var logStacktrace = true
|
||||||
if (exception is MessageSender.Error) {
|
|
||||||
|
when (exception) {
|
||||||
|
// No need for the stack trace for HTTP errors
|
||||||
|
is HTTP.HTTPRequestFailedException -> {
|
||||||
|
logStacktrace = false
|
||||||
|
|
||||||
|
if (exception.statusCode == 429) { this.handlePermanentFailure(exception) }
|
||||||
|
else { this.handleFailure(exception) }
|
||||||
|
}
|
||||||
|
is MessageSender.Error -> {
|
||||||
if (!exception.isRetryable) { this.handlePermanentFailure(exception) }
|
if (!exception.isRetryable) { this.handlePermanentFailure(exception) }
|
||||||
|
else { this.handleFailure(exception) }
|
||||||
}
|
}
|
||||||
if (exception is OnionRequestAPI.HTTPRequestFailedAtDestinationException && exception.statusCode == 429) {
|
else -> this.handleFailure(exception)
|
||||||
this.handlePermanentFailure(exception)
|
|
||||||
}
|
}
|
||||||
this.handleFailure(exception)
|
|
||||||
|
if (logStacktrace) { Log.e(TAG, "Couldn't send message due to error", exception) }
|
||||||
|
else { Log.e(TAG, "Couldn't send message due to error: ${exception.message}") }
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
promise.get()
|
promise.get()
|
||||||
|
@ -383,7 +383,11 @@ object OpenGroupApi {
|
|||||||
}
|
}
|
||||||
return if (request.useOnionRouting) {
|
return if (request.useOnionRouting) {
|
||||||
OnionRequestAPI.sendOnionRequest(requestBuilder.build(), request.server, publicKey).fail { e ->
|
OnionRequestAPI.sendOnionRequest(requestBuilder.build(), request.server, publicKey).fail { e ->
|
||||||
Log.e("SOGS", "Failed onion request", e)
|
when (e) {
|
||||||
|
// No need for the stack trace for HTTP errors
|
||||||
|
is HTTP.HTTPRequestFailedException -> Log.e("SOGS", "Failed onion request: ${e.message}")
|
||||||
|
else -> Log.e("SOGS", "Failed onion request", e)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Promise.ofFail(IllegalStateException("It's currently not allowed to send non onion routed requests."))
|
Promise.ofFail(IllegalStateException("It's currently not allowed to send non onion routed requests."))
|
||||||
|
@ -78,8 +78,8 @@ object OnionRequestAPI {
|
|||||||
// endregion
|
// endregion
|
||||||
|
|
||||||
class HTTPRequestFailedBlindingRequiredException(statusCode: Int, json: Map<*, *>, destination: String): HTTPRequestFailedAtDestinationException(statusCode, json, destination)
|
class HTTPRequestFailedBlindingRequiredException(statusCode: Int, json: Map<*, *>, destination: String): HTTPRequestFailedAtDestinationException(statusCode, json, destination)
|
||||||
open class HTTPRequestFailedAtDestinationException(val statusCode: Int, val json: Map<*, *>, val destination: String)
|
open class HTTPRequestFailedAtDestinationException(statusCode: Int, json: Map<*, *>, val destination: String)
|
||||||
: Exception("HTTP request failed at destination ($destination) with status code $statusCode.")
|
: HTTP.HTTPRequestFailedException(statusCode, json, "HTTP request failed at destination ($destination) with status code $statusCode.")
|
||||||
class InsufficientSnodesException : Exception("Couldn't find enough snodes to build a path.")
|
class InsufficientSnodesException : Exception("Couldn't find enough snodes to build a path.")
|
||||||
|
|
||||||
private data class OnionBuildingResult(
|
private data class OnionBuildingResult(
|
||||||
|
@ -2,6 +2,7 @@ package org.session.libsession.utilities
|
|||||||
|
|
||||||
import okhttp3.HttpUrl
|
import okhttp3.HttpUrl
|
||||||
import org.session.libsession.messaging.file_server.FileServerApi
|
import org.session.libsession.messaging.file_server.FileServerApi
|
||||||
|
import org.session.libsignal.utilities.HTTP
|
||||||
import org.session.libsignal.utilities.Log
|
import org.session.libsignal.utilities.Log
|
||||||
import java.io.*
|
import java.io.*
|
||||||
|
|
||||||
@ -40,7 +41,11 @@ object DownloadUtilities {
|
|||||||
outputStream.write(it)
|
outputStream.write(it)
|
||||||
}
|
}
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
Log.e("Loki", "Couldn't download attachment.", e)
|
when (e) {
|
||||||
|
// No need for the stack trace for HTTP errors
|
||||||
|
is HTTP.HTTPRequestFailedException -> Log.e("Loki", "Couldn't download attachment due to error: ${e.message}")
|
||||||
|
else -> Log.e("Loki", "Couldn't download attachment", e)
|
||||||
|
}
|
||||||
throw e
|
throw e
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,6 +12,7 @@ import javax.net.ssl.SSLContext
|
|||||||
import javax.net.ssl.X509TrustManager
|
import javax.net.ssl.X509TrustManager
|
||||||
|
|
||||||
object HTTP {
|
object HTTP {
|
||||||
|
var isConnectedToNetwork: (() -> Boolean) = { false }
|
||||||
|
|
||||||
private val seedNodeConnection by lazy {
|
private val seedNodeConnection by lazy {
|
||||||
OkHttpClient().newBuilder()
|
OkHttpClient().newBuilder()
|
||||||
@ -64,8 +65,12 @@ object HTTP {
|
|||||||
|
|
||||||
private const val timeout: Long = 120
|
private const val timeout: Long = 120
|
||||||
|
|
||||||
class HTTPRequestFailedException(val statusCode: Int, val json: Map<*, *>?)
|
open class HTTPRequestFailedException(
|
||||||
: kotlin.Exception("HTTP request failed with status code $statusCode.")
|
val statusCode: Int,
|
||||||
|
val json: Map<*, *>?,
|
||||||
|
message: String = "HTTP request failed with status code $statusCode"
|
||||||
|
) : kotlin.Exception(message)
|
||||||
|
class HTTPNoNetworkException : HTTPRequestFailedException(0, null, "No network connection")
|
||||||
|
|
||||||
enum class Verb(val rawValue: String) {
|
enum class Verb(val rawValue: String) {
|
||||||
GET("GET"), PUT("PUT"), POST("POST"), DELETE("DELETE")
|
GET("GET"), PUT("PUT"), POST("POST"), DELETE("DELETE")
|
||||||
@ -120,8 +125,11 @@ object HTTP {
|
|||||||
response = connection.newCall(request.build()).execute()
|
response = connection.newCall(request.build()).execute()
|
||||||
} catch (exception: Exception) {
|
} catch (exception: Exception) {
|
||||||
Log.d("Loki", "${verb.rawValue} request to $url failed due to error: ${exception.localizedMessage}.")
|
Log.d("Loki", "${verb.rawValue} request to $url failed due to error: ${exception.localizedMessage}.")
|
||||||
|
|
||||||
|
if (!isConnectedToNetwork()) { throw HTTPNoNetworkException() }
|
||||||
|
|
||||||
// Override the actual error so that we can correctly catch failed requests in OnionRequestAPI
|
// Override the actual error so that we can correctly catch failed requests in OnionRequestAPI
|
||||||
throw HTTPRequestFailedException(0, null)
|
throw HTTPRequestFailedException(0, null, "HTTP request failed due to: ${exception.message}")
|
||||||
}
|
}
|
||||||
return when (val statusCode = response.code()) {
|
return when (val statusCode = response.code()) {
|
||||||
200 -> {
|
200 -> {
|
||||||
|
Loading…
Reference in New Issue
Block a user