MatrixError: rename the constants to follow the spec
This commit is contained in:
parent
5435a1739e
commit
670d4dc34e
matrix-sdk-android/src/main/java/im/vector/matrix/android
api/failure
internal
crypto/keysbackup
session
vector/src/main/java/im/vector/riotx
@ -29,41 +29,41 @@ data class MatrixError(
|
|||||||
@Json(name = "error") val message: String,
|
@Json(name = "error") val message: String,
|
||||||
|
|
||||||
@Json(name = "consent_uri") val consentUri: String? = null,
|
@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 = "limit_type") val limitType: String? = null,
|
||||||
@Json(name = "admin_contact") val adminUri: 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,
|
@Json(name = "retry_after_ms") val retryAfterMillis: Long? = null,
|
||||||
// For UNAUTHORIZED
|
// For M_UNAUTHORIZED
|
||||||
@Json(name = "soft_logout") val isSoftLogout: Boolean? = null
|
@Json(name = "soft_logout") val isSoftLogout: Boolean? = null
|
||||||
) {
|
) {
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
const val FORBIDDEN = "M_FORBIDDEN"
|
const val M_FORBIDDEN = "M_FORBIDDEN"
|
||||||
const val UNKNOWN = "M_UNKNOWN"
|
const val M_UNKNOWN = "M_UNKNOWN"
|
||||||
const val UNKNOWN_TOKEN = "M_UNKNOWN_TOKEN"
|
const val M_UNKNOWN_TOKEN = "M_UNKNOWN_TOKEN"
|
||||||
const val MISSING_TOKEN = "M_MISSING_TOKEN"
|
const val M_MISSING_TOKEN = "M_MISSING_TOKEN"
|
||||||
const val BAD_JSON = "M_BAD_JSON"
|
const val M_BAD_JSON = "M_BAD_JSON"
|
||||||
const val NOT_JSON = "M_NOT_JSON"
|
const val M_NOT_JSON = "M_NOT_JSON"
|
||||||
const val NOT_FOUND = "M_NOT_FOUND"
|
const val M_NOT_FOUND = "M_NOT_FOUND"
|
||||||
const val LIMIT_EXCEEDED = "M_LIMIT_EXCEEDED"
|
const val M_LIMIT_EXCEEDED = "M_LIMIT_EXCEEDED"
|
||||||
const val USER_IN_USE = "M_USER_IN_USE"
|
const val M_USER_IN_USE = "M_USER_IN_USE"
|
||||||
const val ROOM_IN_USE = "M_ROOM_IN_USE"
|
const val M_ROOM_IN_USE = "M_ROOM_IN_USE"
|
||||||
const val BAD_PAGINATION = "M_BAD_PAGINATION"
|
const val M_BAD_PAGINATION = "M_BAD_PAGINATION"
|
||||||
const val UNAUTHORIZED = "M_UNAUTHORIZED"
|
const val M_UNAUTHORIZED = "M_UNAUTHORIZED"
|
||||||
const val OLD_VERSION = "M_OLD_VERSION"
|
const val M_OLD_VERSION = "M_OLD_VERSION"
|
||||||
const val UNRECOGNIZED = "M_UNRECOGNIZED"
|
const val M_UNRECOGNIZED = "M_UNRECOGNIZED"
|
||||||
|
|
||||||
const val LOGIN_EMAIL_URL_NOT_YET = "M_LOGIN_EMAIL_URL_NOT_YET"
|
const val M_LOGIN_EMAIL_URL_NOT_YET = "M_LOGIN_EMAIL_URL_NOT_YET"
|
||||||
const val THREEPID_AUTH_FAILED = "M_THREEPID_AUTH_FAILED"
|
const val M_THREEPID_AUTH_FAILED = "M_THREEPID_AUTH_FAILED"
|
||||||
// Error code returned by the server when no account matches the given 3pid
|
// Error code returned by the server when no account matches the given 3pid
|
||||||
const val THREEPID_NOT_FOUND = "M_THREEPID_NOT_FOUND"
|
const val M_THREEPID_NOT_FOUND = "M_THREEPID_NOT_FOUND"
|
||||||
const val THREEPID_IN_USE = "M_THREEPID_IN_USE"
|
const val M_THREEPID_IN_USE = "M_THREEPID_IN_USE"
|
||||||
const val SERVER_NOT_TRUSTED = "M_SERVER_NOT_TRUSTED"
|
const val M_SERVER_NOT_TRUSTED = "M_SERVER_NOT_TRUSTED"
|
||||||
const val TOO_LARGE = "M_TOO_LARGE"
|
const val M_TOO_LARGE = "M_TOO_LARGE"
|
||||||
const val M_CONSENT_NOT_GIVEN = "M_CONSENT_NOT_GIVEN"
|
const val M_CONSENT_NOT_GIVEN = "M_CONSENT_NOT_GIVEN"
|
||||||
const val RESOURCE_LIMIT_EXCEEDED = "M_RESOURCE_LIMIT_EXCEEDED"
|
const val M_RESOURCE_LIMIT_EXCEEDED = "M_RESOURCE_LIMIT_EXCEEDED"
|
||||||
const val WRONG_ROOM_KEYS_VERSION = "M_WRONG_ROOM_KEYS_VERSION"
|
const val M_WRONG_ROOM_KEYS_VERSION = "M_WRONG_ROOM_KEYS_VERSION"
|
||||||
|
|
||||||
// Possible value for "limit_type"
|
// Possible value for "limit_type"
|
||||||
const val LIMIT_TYPE_MAU = "monthly_active_user"
|
const val LIMIT_TYPE_MAU = "monthly_active_user"
|
||||||
|
8
matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/keysbackup/KeysBackup.kt
8
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) {
|
override fun onFailure(failure: Throwable) {
|
||||||
if (failure is Failure.ServerError
|
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
|
// Workaround because the homeserver currently returns M_NOT_FOUND when there is no key backup
|
||||||
callback.onSuccess(null)
|
callback.onSuccess(null)
|
||||||
} else {
|
} else {
|
||||||
@ -830,7 +830,7 @@ internal class KeysBackup @Inject constructor(
|
|||||||
|
|
||||||
override fun onFailure(failure: Throwable) {
|
override fun onFailure(failure: Throwable) {
|
||||||
if (failure is Failure.ServerError
|
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
|
// Workaround because the homeserver currently returns M_NOT_FOUND when there is no key backup
|
||||||
callback.onSuccess(null)
|
callback.onSuccess(null)
|
||||||
} else {
|
} else {
|
||||||
@ -1209,8 +1209,8 @@ internal class KeysBackup @Inject constructor(
|
|||||||
Timber.e(failure, "backupKeys: backupKeys failed.")
|
Timber.e(failure, "backupKeys: backupKeys failed.")
|
||||||
|
|
||||||
when (failure.error.code) {
|
when (failure.error.code) {
|
||||||
MatrixError.NOT_FOUND,
|
MatrixError.M_NOT_FOUND,
|
||||||
MatrixError.WRONG_ROOM_KEYS_VERSION -> {
|
MatrixError.M_WRONG_ROOM_KEYS_VERSION -> {
|
||||||
// Backup has been deleted on the server, or we are not using the last backup version
|
// Backup has been deleted on the server, or we are not using the last backup version
|
||||||
keysBackupStateManager.state = KeysBackupState.WrongBackUpVersion
|
keysBackupStateManager.state = KeysBackupState.WrongBackUpVersion
|
||||||
backupAllGroupSessionsCallback?.onFailure(failure)
|
backupAllGroupSessionsCallback?.onFailure(failure)
|
||||||
|
@ -79,7 +79,7 @@ internal class SendEventWorker constructor(context: Context, params: WorkerParam
|
|||||||
|
|
||||||
private fun Throwable.shouldBeRetried(): Boolean {
|
private fun Throwable.shouldBeRetried(): Boolean {
|
||||||
return this is Failure.NetworkConnection
|
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) {
|
private suspend fun sendEvent(eventId: String, eventType: String, content: Content?, roomId: String) {
|
||||||
|
@ -74,7 +74,7 @@ internal class DefaultSyncTask @Inject constructor(private val syncAPI: SyncAPI,
|
|||||||
} catch (throwable: Throwable) {
|
} catch (throwable: Throwable) {
|
||||||
// Intercept 401
|
// Intercept 401
|
||||||
if (throwable is Failure.ServerError
|
if (throwable is Failure.ServerError
|
||||||
&& throwable.error.code == MatrixError.UNKNOWN_TOKEN) {
|
&& throwable.error.code == MatrixError.M_UNKNOWN_TOKEN) {
|
||||||
sessionParamsStore.delete(userId)
|
sessionParamsStore.delete(userId)
|
||||||
}
|
}
|
||||||
throw throwable
|
throw throwable
|
||||||
|
2
matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/job/SyncService.kt
2
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
|
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
|
// No token or invalid token, stop the thread
|
||||||
stopSelf()
|
stopSelf()
|
||||||
}
|
}
|
||||||
|
@ -141,7 +141,7 @@ internal class SyncThread @Inject constructor(private val syncTask: SyncTask,
|
|||||||
} else if (failure is Failure.Cancelled) {
|
} else if (failure is Failure.Cancelled) {
|
||||||
Timber.v("Cancelled")
|
Timber.v("Cancelled")
|
||||||
} else if (failure is Failure.ServerError
|
} 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
|
// No token or invalid token, stop the thread
|
||||||
Timber.w(failure)
|
Timber.w(failure)
|
||||||
updateStateTo(SyncState.KILLING)
|
updateStateTo(SyncState.KILLING)
|
||||||
|
@ -52,23 +52,23 @@ class ErrorFormatter @Inject constructor(private val stringProvider: StringProvi
|
|||||||
// Special case for terms and conditions
|
// Special case for terms and conditions
|
||||||
stringProvider.getString(R.string.error_terms_not_accepted)
|
stringProvider.getString(R.string.error_terms_not_accepted)
|
||||||
}
|
}
|
||||||
throwable.error.code == MatrixError.FORBIDDEN
|
throwable.error.code == MatrixError.M_FORBIDDEN
|
||||||
&& throwable.error.message == "Invalid password" -> {
|
&& throwable.error.message == "Invalid password" -> {
|
||||||
stringProvider.getString(R.string.auth_invalid_login_param)
|
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)
|
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)
|
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)
|
stringProvider.getString(R.string.login_error_not_json)
|
||||||
}
|
}
|
||||||
throwable.error.code == MatrixError.LIMIT_EXCEEDED -> {
|
throwable.error.code == MatrixError.M_LIMIT_EXCEEDED -> {
|
||||||
limitExceededError(throwable.error)
|
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)
|
stringProvider.getString(R.string.login_reset_password_error_not_found)
|
||||||
}
|
}
|
||||||
else -> {
|
else -> {
|
||||||
|
@ -21,6 +21,6 @@ import im.vector.matrix.android.api.failure.MatrixError
|
|||||||
import javax.net.ssl.HttpsURLConnection
|
import javax.net.ssl.HttpsURLConnection
|
||||||
|
|
||||||
fun Throwable.is401(): Boolean {
|
fun Throwable.is401(): Boolean {
|
||||||
return (this is Failure.ServerError && this.httpCode == HttpsURLConnection.HTTP_UNAUTHORIZED /* 401 */
|
return (this is Failure.ServerError && httpCode == HttpsURLConnection.HTTP_UNAUTHORIZED /* 401 */
|
||||||
&& this.error.code == MatrixError.UNAUTHORIZED)
|
&& error.code == MatrixError.M_UNAUTHORIZED)
|
||||||
}
|
}
|
||||||
|
@ -78,7 +78,7 @@ abstract class AbstractLoginFragment : VectorBaseFragment(), OnBackPressed {
|
|||||||
private fun showError(throwable: Throwable) {
|
private fun showError(throwable: Throwable) {
|
||||||
when (throwable) {
|
when (throwable) {
|
||||||
is Failure.ServerError -> {
|
is Failure.ServerError -> {
|
||||||
if (throwable.error.code == MatrixError.FORBIDDEN
|
if (throwable.error.code == MatrixError.M_FORBIDDEN
|
||||||
&& throwable.httpCode == HttpsURLConnection.HTTP_FORBIDDEN /* 403 */) {
|
&& throwable.httpCode == HttpsURLConnection.HTTP_FORBIDDEN /* 403 */) {
|
||||||
AlertDialog.Builder(requireActivity())
|
AlertDialog.Builder(requireActivity())
|
||||||
.setTitle(R.string.dialog_title_error)
|
.setTitle(R.string.dialog_title_error)
|
||||||
|
@ -198,7 +198,7 @@ class LoginFragment @Inject constructor(
|
|||||||
is Fail -> {
|
is Fail -> {
|
||||||
val error = state.asyncLoginAction.error
|
val error = state.asyncLoginAction.error
|
||||||
if (error is Failure.ServerError
|
if (error is Failure.ServerError
|
||||||
&& error.error.code == MatrixError.FORBIDDEN
|
&& error.error.code == MatrixError.M_FORBIDDEN
|
||||||
&& error.error.message.isEmpty()) {
|
&& error.error.message.isEmpty()) {
|
||||||
// Login with email, but email unknown
|
// Login with email, but email unknown
|
||||||
loginFieldTil.error = getString(R.string.login_login_with_email_error)
|
loginFieldTil.error = getString(R.string.login_login_with_email_error)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user