diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/failure/MatrixError.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/failure/MatrixError.kt index 06c2671d36..fb35940f34 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/failure/MatrixError.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/failure/MatrixError.kt @@ -29,41 +29,41 @@ data class MatrixError( @Json(name = "error") val message: String, @Json(name = "consent_uri") val consentUri: String? = null, - // For RESOURCE_LIMIT_EXCEEDED + // For M_RESOURCE_LIMIT_EXCEEDED @Json(name = "limit_type") val limitType: String? = null, @Json(name = "admin_contact") val adminUri: String? = null, - // For LIMIT_EXCEEDED + // For M_LIMIT_EXCEEDED @Json(name = "retry_after_ms") val retryAfterMillis: Long? = null, - // For UNAUTHORIZED + // For M_UNAUTHORIZED @Json(name = "soft_logout") val isSoftLogout: Boolean? = null ) { companion object { - const val FORBIDDEN = "M_FORBIDDEN" - const val UNKNOWN = "M_UNKNOWN" - const val UNKNOWN_TOKEN = "M_UNKNOWN_TOKEN" - const val MISSING_TOKEN = "M_MISSING_TOKEN" - const val BAD_JSON = "M_BAD_JSON" - const val NOT_JSON = "M_NOT_JSON" - const val NOT_FOUND = "M_NOT_FOUND" - const val LIMIT_EXCEEDED = "M_LIMIT_EXCEEDED" - const val USER_IN_USE = "M_USER_IN_USE" - const val ROOM_IN_USE = "M_ROOM_IN_USE" - const val BAD_PAGINATION = "M_BAD_PAGINATION" - const val UNAUTHORIZED = "M_UNAUTHORIZED" - const val OLD_VERSION = "M_OLD_VERSION" - const val UNRECOGNIZED = "M_UNRECOGNIZED" + const val M_FORBIDDEN = "M_FORBIDDEN" + const val M_UNKNOWN = "M_UNKNOWN" + const val M_UNKNOWN_TOKEN = "M_UNKNOWN_TOKEN" + const val M_MISSING_TOKEN = "M_MISSING_TOKEN" + const val M_BAD_JSON = "M_BAD_JSON" + const val M_NOT_JSON = "M_NOT_JSON" + const val M_NOT_FOUND = "M_NOT_FOUND" + const val M_LIMIT_EXCEEDED = "M_LIMIT_EXCEEDED" + const val M_USER_IN_USE = "M_USER_IN_USE" + const val M_ROOM_IN_USE = "M_ROOM_IN_USE" + const val M_BAD_PAGINATION = "M_BAD_PAGINATION" + const val M_UNAUTHORIZED = "M_UNAUTHORIZED" + const val M_OLD_VERSION = "M_OLD_VERSION" + const val M_UNRECOGNIZED = "M_UNRECOGNIZED" - const val LOGIN_EMAIL_URL_NOT_YET = "M_LOGIN_EMAIL_URL_NOT_YET" - const val THREEPID_AUTH_FAILED = "M_THREEPID_AUTH_FAILED" + const val M_LOGIN_EMAIL_URL_NOT_YET = "M_LOGIN_EMAIL_URL_NOT_YET" + const val M_THREEPID_AUTH_FAILED = "M_THREEPID_AUTH_FAILED" // Error code returned by the server when no account matches the given 3pid - const val THREEPID_NOT_FOUND = "M_THREEPID_NOT_FOUND" - const val THREEPID_IN_USE = "M_THREEPID_IN_USE" - const val SERVER_NOT_TRUSTED = "M_SERVER_NOT_TRUSTED" - const val TOO_LARGE = "M_TOO_LARGE" + const val M_THREEPID_NOT_FOUND = "M_THREEPID_NOT_FOUND" + const val M_THREEPID_IN_USE = "M_THREEPID_IN_USE" + const val M_SERVER_NOT_TRUSTED = "M_SERVER_NOT_TRUSTED" + const val M_TOO_LARGE = "M_TOO_LARGE" const val M_CONSENT_NOT_GIVEN = "M_CONSENT_NOT_GIVEN" - const val RESOURCE_LIMIT_EXCEEDED = "M_RESOURCE_LIMIT_EXCEEDED" - const val WRONG_ROOM_KEYS_VERSION = "M_WRONG_ROOM_KEYS_VERSION" + const val M_RESOURCE_LIMIT_EXCEEDED = "M_RESOURCE_LIMIT_EXCEEDED" + const val M_WRONG_ROOM_KEYS_VERSION = "M_WRONG_ROOM_KEYS_VERSION" // Possible value for "limit_type" const val LIMIT_TYPE_MAU = "monthly_active_user" diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/keysbackup/KeysBackup.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/keysbackup/KeysBackup.kt index 1cc1a8a05a..91b3d6b056 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/keysbackup/KeysBackup.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/keysbackup/KeysBackup.kt @@ -807,7 +807,7 @@ internal class KeysBackup @Inject constructor( override fun onFailure(failure: Throwable) { if (failure is Failure.ServerError - && failure.error.code == MatrixError.NOT_FOUND) { + && failure.error.code == MatrixError.M_NOT_FOUND) { // Workaround because the homeserver currently returns M_NOT_FOUND when there is no key backup callback.onSuccess(null) } else { @@ -830,7 +830,7 @@ internal class KeysBackup @Inject constructor( override fun onFailure(failure: Throwable) { if (failure is Failure.ServerError - && failure.error.code == MatrixError.NOT_FOUND) { + && failure.error.code == MatrixError.M_NOT_FOUND) { // Workaround because the homeserver currently returns M_NOT_FOUND when there is no key backup callback.onSuccess(null) } else { @@ -1209,8 +1209,8 @@ internal class KeysBackup @Inject constructor( Timber.e(failure, "backupKeys: backupKeys failed.") when (failure.error.code) { - MatrixError.NOT_FOUND, - MatrixError.WRONG_ROOM_KEYS_VERSION -> { + MatrixError.M_NOT_FOUND, + MatrixError.M_WRONG_ROOM_KEYS_VERSION -> { // Backup has been deleted on the server, or we are not using the last backup version keysBackupStateManager.state = KeysBackupState.WrongBackUpVersion backupAllGroupSessionsCallback?.onFailure(failure) diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/send/SendEventWorker.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/send/SendEventWorker.kt index 183b0ad9b8..6527113054 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/send/SendEventWorker.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/send/SendEventWorker.kt @@ -79,7 +79,7 @@ internal class SendEventWorker constructor(context: Context, params: WorkerParam private fun Throwable.shouldBeRetried(): Boolean { return this is Failure.NetworkConnection - || (this is Failure.ServerError && this.error.code == MatrixError.LIMIT_EXCEEDED) + || (this is Failure.ServerError && error.code == MatrixError.M_LIMIT_EXCEEDED) } private suspend fun sendEvent(eventId: String, eventType: String, content: Content?, roomId: String) { diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/SyncTask.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/SyncTask.kt index 51c02456d7..197835d44b 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/SyncTask.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/SyncTask.kt @@ -74,7 +74,7 @@ internal class DefaultSyncTask @Inject constructor(private val syncAPI: SyncAPI, } catch (throwable: Throwable) { // Intercept 401 if (throwable is Failure.ServerError - && throwable.error.code == MatrixError.UNKNOWN_TOKEN) { + && throwable.error.code == MatrixError.M_UNKNOWN_TOKEN) { sessionParamsStore.delete(userId) } throw throwable diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/job/SyncService.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/job/SyncService.kt index 4e57aa5be1..71734cdfe7 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/job/SyncService.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/job/SyncService.kt @@ -147,7 +147,7 @@ open class SyncService : Service() { } if (failure is Failure.ServerError - && (failure.error.code == MatrixError.UNKNOWN_TOKEN || failure.error.code == MatrixError.MISSING_TOKEN)) { + && (failure.error.code == MatrixError.M_UNKNOWN_TOKEN || failure.error.code == MatrixError.M_MISSING_TOKEN)) { // No token or invalid token, stop the thread stopSelf() } diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/job/SyncThread.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/job/SyncThread.kt index d8de292d70..8b149f57d5 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/job/SyncThread.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/job/SyncThread.kt @@ -141,7 +141,7 @@ internal class SyncThread @Inject constructor(private val syncTask: SyncTask, } else if (failure is Failure.Cancelled) { Timber.v("Cancelled") } else if (failure is Failure.ServerError - && (failure.error.code == MatrixError.UNKNOWN_TOKEN || failure.error.code == MatrixError.MISSING_TOKEN)) { + && (failure.error.code == MatrixError.M_UNKNOWN_TOKEN || failure.error.code == MatrixError.M_MISSING_TOKEN)) { // No token or invalid token, stop the thread Timber.w(failure) updateStateTo(SyncState.KILLING) diff --git a/vector/src/main/java/im/vector/riotx/core/error/ErrorFormatter.kt b/vector/src/main/java/im/vector/riotx/core/error/ErrorFormatter.kt index 6f34415d9a..d4a2160ed1 100644 --- a/vector/src/main/java/im/vector/riotx/core/error/ErrorFormatter.kt +++ b/vector/src/main/java/im/vector/riotx/core/error/ErrorFormatter.kt @@ -52,23 +52,23 @@ class ErrorFormatter @Inject constructor(private val stringProvider: StringProvi // Special case for terms and conditions stringProvider.getString(R.string.error_terms_not_accepted) } - throwable.error.code == MatrixError.FORBIDDEN + throwable.error.code == MatrixError.M_FORBIDDEN && throwable.error.message == "Invalid password" -> { stringProvider.getString(R.string.auth_invalid_login_param) } - throwable.error.code == MatrixError.USER_IN_USE -> { + throwable.error.code == MatrixError.M_USER_IN_USE -> { stringProvider.getString(R.string.login_signup_error_user_in_use) } - throwable.error.code == MatrixError.BAD_JSON -> { + throwable.error.code == MatrixError.M_BAD_JSON -> { stringProvider.getString(R.string.login_error_bad_json) } - throwable.error.code == MatrixError.NOT_JSON -> { + throwable.error.code == MatrixError.M_NOT_JSON -> { stringProvider.getString(R.string.login_error_not_json) } - throwable.error.code == MatrixError.LIMIT_EXCEEDED -> { + throwable.error.code == MatrixError.M_LIMIT_EXCEEDED -> { limitExceededError(throwable.error) } - throwable.error.code == MatrixError.THREEPID_NOT_FOUND -> { + throwable.error.code == MatrixError.M_THREEPID_NOT_FOUND -> { stringProvider.getString(R.string.login_reset_password_error_not_found) } else -> { diff --git a/vector/src/main/java/im/vector/riotx/core/error/Extensions.kt b/vector/src/main/java/im/vector/riotx/core/error/Extensions.kt index dd4257fe1f..614340bd3d 100644 --- a/vector/src/main/java/im/vector/riotx/core/error/Extensions.kt +++ b/vector/src/main/java/im/vector/riotx/core/error/Extensions.kt @@ -21,6 +21,6 @@ import im.vector.matrix.android.api.failure.MatrixError import javax.net.ssl.HttpsURLConnection fun Throwable.is401(): Boolean { - return (this is Failure.ServerError && this.httpCode == HttpsURLConnection.HTTP_UNAUTHORIZED /* 401 */ - && this.error.code == MatrixError.UNAUTHORIZED) + return (this is Failure.ServerError && httpCode == HttpsURLConnection.HTTP_UNAUTHORIZED /* 401 */ + && error.code == MatrixError.M_UNAUTHORIZED) } diff --git a/vector/src/main/java/im/vector/riotx/features/login/AbstractLoginFragment.kt b/vector/src/main/java/im/vector/riotx/features/login/AbstractLoginFragment.kt index 6cca32cf7f..cf8a0fb6f3 100644 --- a/vector/src/main/java/im/vector/riotx/features/login/AbstractLoginFragment.kt +++ b/vector/src/main/java/im/vector/riotx/features/login/AbstractLoginFragment.kt @@ -78,7 +78,7 @@ abstract class AbstractLoginFragment : VectorBaseFragment(), OnBackPressed { private fun showError(throwable: Throwable) { when (throwable) { is Failure.ServerError -> { - if (throwable.error.code == MatrixError.FORBIDDEN + if (throwable.error.code == MatrixError.M_FORBIDDEN && throwable.httpCode == HttpsURLConnection.HTTP_FORBIDDEN /* 403 */) { AlertDialog.Builder(requireActivity()) .setTitle(R.string.dialog_title_error) diff --git a/vector/src/main/java/im/vector/riotx/features/login/LoginFragment.kt b/vector/src/main/java/im/vector/riotx/features/login/LoginFragment.kt index 67935c1ae8..f90e6a8d0b 100644 --- a/vector/src/main/java/im/vector/riotx/features/login/LoginFragment.kt +++ b/vector/src/main/java/im/vector/riotx/features/login/LoginFragment.kt @@ -198,7 +198,7 @@ class LoginFragment @Inject constructor( is Fail -> { val error = state.asyncLoginAction.error if (error is Failure.ServerError - && error.error.code == MatrixError.FORBIDDEN + && error.error.code == MatrixError.M_FORBIDDEN && error.error.message.isEmpty()) { // Login with email, but email unknown loginFieldTil.error = getString(R.string.login_login_with_email_error)