make error description show in the message detail activity

This commit is contained in:
Ryan ZHAO 2021-03-16 16:31:52 +11:00
parent 2e65077b3a
commit 95646ed04e
9 changed files with 20 additions and 16 deletions

View File

@ -44,6 +44,7 @@ import org.session.libsession.messaging.messages.signal.IncomingGroupMessage
import org.session.libsession.messaging.messages.signal.IncomingTextMessage import org.session.libsession.messaging.messages.signal.IncomingTextMessage
import org.session.libsession.messaging.messages.signal.OutgoingTextMessage import org.session.libsession.messaging.messages.signal.OutgoingTextMessage
import org.session.libsession.utilities.preferences.ProfileKeyUtil import org.session.libsession.utilities.preferences.ProfileKeyUtil
import org.session.libsignal.service.loki.utilities.prettifiedDescription
class Storage(context: Context, helper: SQLCipherOpenHelper) : Database(context, helper), StorageProtocol { class Storage(context: Context, helper: SQLCipherOpenHelper) : Database(context, helper), StorageProtocol {
override fun getUserPublicKey(): String? { override fun getUserPublicKey(): String? {
@ -368,6 +369,11 @@ class Storage(context: Context, helper: SQLCipherOpenHelper) : Database(context,
val smsDatabase = DatabaseFactory.getSmsDatabase(context) val smsDatabase = DatabaseFactory.getSmsDatabase(context)
smsDatabase.markAsSentFailed(messageRecord.getId()) smsDatabase.markAsSentFailed(messageRecord.getId())
} }
if (error.localizedMessage != null) {
DatabaseFactory.getLokiMessageDatabase(context).setErrorMessage(messageRecord.getId(), error.localizedMessage!!)
} else {
DatabaseFactory.getLokiMessageDatabase(context).setErrorMessage(messageRecord.getId(), error.javaClass.simpleName)
}
} }
override fun getGroup(groupID: String): GroupRecord? { override fun getGroup(groupID: String): GroupRecord? {

View File

@ -17,7 +17,7 @@ class AttachmentDownloadJob(val attachmentID: Long, val databaseMessageID: Long)
private val MAX_ATTACHMENT_SIZE = 10 * 1024 * 1024 private val MAX_ATTACHMENT_SIZE = 10 * 1024 * 1024
// Error // Error
internal sealed class Error(val description: String) : Exception() { internal sealed class Error(val description: String) : Exception(description) {
object NoAttachment : Error("No such attachment.") object NoAttachment : Error("No such attachment.")
} }

View File

@ -25,7 +25,7 @@ class AttachmentUploadJob(val attachmentID: Long, val threadID: String, val mess
override var failureCount: Int = 0 override var failureCount: Int = 0
// Error // Error
internal sealed class Error(val description: String) : Exception() { internal sealed class Error(val description: String) : Exception(description) {
object NoAttachment : Error("No such attachment.") object NoAttachment : Error("No such attachment.")
} }

View File

@ -11,7 +11,7 @@ object MessageReceiver {
private val lastEncryptionKeyPairRequest = mutableMapOf<String, Long>() private val lastEncryptionKeyPairRequest = mutableMapOf<String, Long>()
internal sealed class Error(val description: String) : Exception() { internal sealed class Error(val description: String) : Exception(description) {
object DuplicateMessage: Error("Duplicate message.") object DuplicateMessage: Error("Duplicate message.")
object InvalidMessage: Error("Invalid message.") object InvalidMessage: Error("Invalid message.")
object UnknownMessage: Error("Unknown message type.") object UnknownMessage: Error("Unknown message type.")

View File

@ -34,7 +34,7 @@ import org.session.libsignal.utilities.logging.Log
object MessageSender { object MessageSender {
// Error // Error
sealed class Error(val description: String) : Exception() { sealed class Error(val description: String) : Exception(description) {
object InvalidMessage : Error("Invalid message.") object InvalidMessage : Error("Invalid message.")
object ProtoConversionFailed : Error("Couldn't convert message to proto.") object ProtoConversionFailed : Error("Couldn't convert message to proto.")
object ProofOfWorkCalculationFailed : Error("Proof of work calculation failed.") object ProofOfWorkCalculationFailed : Error("Proof of work calculation failed.")
@ -202,6 +202,11 @@ object MessageSender {
val preconditionFailure = Exception("Destination should not be contacts or closed groups!") val preconditionFailure = Exception("Destination should not be contacts or closed groups!")
message.sentTimestamp ?: run { message.sentTimestamp = System.currentTimeMillis() } message.sentTimestamp ?: run { message.sentTimestamp = System.currentTimeMillis() }
message.sender = storage.getUserPublicKey() message.sender = storage.getUserPublicKey()
// Set the failure handler (need it here already for precondition failure handling)
fun handleFailure(error: Exception) {
handleFailedMessageSend(message, error)
deferred.reject(error)
}
try { try {
val server: String val server: String
val channel: Long val channel: Long
@ -214,19 +219,12 @@ object MessageSender {
channel = destination.channel channel = destination.channel
} }
} }
// Set the failure handler (need it here already for precondition failure handling)
fun handleFailure(error: Exception) {
handleFailedMessageSend(message, error)
deferred.reject(error)
}
// Validate the message // Validate the message
if (message !is VisibleMessage || !message.isValid()) { if (message !is VisibleMessage || !message.isValid()) {
handleFailure(Error.InvalidMessage)
throw Error.InvalidMessage throw Error.InvalidMessage
} }
// Convert the message to an open group message // Convert the message to an open group message
val openGroupMessage = OpenGroupMessage.from(message, server) ?: kotlin.run { val openGroupMessage = OpenGroupMessage.from(message, server) ?: kotlin.run {
handleFailure(Error.InvalidMessage)
throw Error.InvalidMessage throw Error.InvalidMessage
} }
// Send the result // Send the result
@ -238,7 +236,7 @@ object MessageSender {
handleFailure(it) handleFailure(it)
} }
} catch (exception: Exception) { } catch (exception: Exception) {
deferred.reject(exception) handleFailure(exception)
} }
return deferred.promise return deferred.promise
} }

View File

@ -42,7 +42,7 @@ open class DotNetAPI {
internal enum class HTTPVerb { GET, PUT, POST, DELETE, PATCH } internal enum class HTTPVerb { GET, PUT, POST, DELETE, PATCH }
// Error // Error
internal sealed class Error(val description: String) : Exception() { internal sealed class Error(val description: String) : Exception(description) {
object Generic : Error("An error occurred.") object Generic : Error("An error occurred.")
object InvalidURL : Error("Invalid URL.") object InvalidURL : Error("Invalid URL.")
object ParsingFailed : Error("Invalid file server response.") object ParsingFailed : Error("Invalid file server response.")

View File

@ -10,7 +10,7 @@ import java.security.SecureRandom
object MessageWrapper { object MessageWrapper {
// region Types // region Types
sealed class Error(val description: String) : Exception() { sealed class Error(val description: String) : Exception(description) {
object FailedToWrapData : Error("Failed to wrap data.") object FailedToWrapData : Error("Failed to wrap data.")
object FailedToWrapMessageInEnvelope : Error("Failed to wrap message in envelope.") object FailedToWrapMessageInEnvelope : Error("Failed to wrap message in envelope.")
object FailedToWrapEnvelopeInWebSocketMessage : Error("Failed to wrap envelope in web socket message.") object FailedToWrapEnvelopeInWebSocketMessage : Error("Failed to wrap envelope in web socket message.")

View File

@ -45,7 +45,7 @@ object SnodeAPI {
internal var powDifficulty = 1 internal var powDifficulty = 1
// Error // Error
internal sealed class Error(val description: String) : Exception() { internal sealed class Error(val description: String) : Exception(description) {
object Generic : Error("An error occurred.") object Generic : Error("An error occurred.")
object ClockOutOfSync : Error("The user's clock is out of sync with the service node network.") object ClockOutOfSync : Error("The user's clock is out of sync with the service node network.")
object RandomSnodePoolUpdatingFailed : Error("Failed to update random service node pool.") object RandomSnodePoolUpdatingFailed : Error("Failed to update random service node pool.")

View File

@ -50,7 +50,7 @@ class MnemonicCodec(private val loadFileContents: (String) -> String) {
} }
} }
sealed class DecodingError(val description: String) : Exception() { sealed class DecodingError(val description: String) : Exception(description) {
object Generic : DecodingError("Something went wrong. Please check your mnemonic and try again.") object Generic : DecodingError("Something went wrong. Please check your mnemonic and try again.")
object InputTooShort : DecodingError("Looks like you didn't enter enough words. Please check your mnemonic and try again.") object InputTooShort : DecodingError("Looks like you didn't enter enough words. Please check your mnemonic and try again.")
object MissingLastWord : DecodingError("You seem to be missing the last word of your mnemonic. Please check what you entered and try again.") object MissingLastWord : DecodingError("You seem to be missing the last word of your mnemonic. Please check what you entered and try again.")