From c54358831faece6549ae51b95d7dd48544e5d360 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Fri, 20 Dec 2019 17:45:32 +0100 Subject: [PATCH] Group throwable extension together --- .../matrix/android/api/failure}/Extensions.kt | 16 +++++++++------- .../vector/matrix/android/api/failure/Failure.kt | 2 -- .../login/LoginGenericTextInputFormFragment.kt | 2 +- ...LoginResetPasswordMailConfirmationFragment.kt | 2 +- .../features/login/LoginWaitForEmailFragment.kt | 2 +- 5 files changed, 12 insertions(+), 12 deletions(-) rename {vector/src/main/java/im/vector/riotx/core/error => matrix-sdk-android/src/main/java/im/vector/matrix/android/api/failure}/Extensions.kt (60%) diff --git a/vector/src/main/java/im/vector/riotx/core/error/Extensions.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/failure/Extensions.kt similarity index 60% rename from vector/src/main/java/im/vector/riotx/core/error/Extensions.kt rename to matrix-sdk-android/src/main/java/im/vector/matrix/android/api/failure/Extensions.kt index 614340bd3d..a3b5ce39eb 100644 --- a/vector/src/main/java/im/vector/riotx/core/error/Extensions.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/failure/Extensions.kt @@ -14,13 +14,15 @@ * limitations under the License. */ -package im.vector.riotx.core.error +package im.vector.matrix.android.api.failure -import im.vector.matrix.android.api.failure.Failure -import im.vector.matrix.android.api.failure.MatrixError import javax.net.ssl.HttpsURLConnection -fun Throwable.is401(): Boolean { - return (this is Failure.ServerError && httpCode == HttpsURLConnection.HTTP_UNAUTHORIZED /* 401 */ - && error.code == MatrixError.M_UNAUTHORIZED) -} +fun Throwable.is401() = + this is Failure.ServerError + && httpCode == HttpsURLConnection.HTTP_UNAUTHORIZED /* 401 */ + && error.code == MatrixError.M_UNAUTHORIZED + +fun Throwable.isTokenError() = + this is Failure.ServerError + && (error.code == MatrixError.M_UNKNOWN_TOKEN || error.code == MatrixError.M_MISSING_TOKEN) diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/failure/Failure.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/failure/Failure.kt index 611b2fb7d3..4d44e3346b 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/failure/Failure.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/failure/Failure.kt @@ -44,5 +44,3 @@ sealed class Failure(cause: Throwable? = null) : Throwable(cause = cause) { abstract class FeatureFailure : Failure() } - -fun Throwable.isTokenError() = this is Failure.ServerError && (this.error.code == MatrixError.M_UNKNOWN_TOKEN || this.error.code == MatrixError.M_MISSING_TOKEN) diff --git a/vector/src/main/java/im/vector/riotx/features/login/LoginGenericTextInputFormFragment.kt b/vector/src/main/java/im/vector/riotx/features/login/LoginGenericTextInputFormFragment.kt index 64fb01fa5f..3ee1cd6d64 100644 --- a/vector/src/main/java/im/vector/riotx/features/login/LoginGenericTextInputFormFragment.kt +++ b/vector/src/main/java/im/vector/riotx/features/login/LoginGenericTextInputFormFragment.kt @@ -30,8 +30,8 @@ import com.google.i18n.phonenumbers.PhoneNumberUtil import com.jakewharton.rxbinding3.widget.textChanges import im.vector.matrix.android.api.auth.registration.RegisterThreePid import im.vector.matrix.android.api.failure.Failure +import im.vector.matrix.android.api.failure.is401 import im.vector.riotx.R -import im.vector.riotx.core.error.is401 import im.vector.riotx.core.extensions.hideKeyboard import im.vector.riotx.core.extensions.isEmail import im.vector.riotx.core.extensions.setTextOrHide diff --git a/vector/src/main/java/im/vector/riotx/features/login/LoginResetPasswordMailConfirmationFragment.kt b/vector/src/main/java/im/vector/riotx/features/login/LoginResetPasswordMailConfirmationFragment.kt index e7ddc78853..cace48b7f2 100644 --- a/vector/src/main/java/im/vector/riotx/features/login/LoginResetPasswordMailConfirmationFragment.kt +++ b/vector/src/main/java/im/vector/riotx/features/login/LoginResetPasswordMailConfirmationFragment.kt @@ -20,8 +20,8 @@ import androidx.appcompat.app.AlertDialog import butterknife.OnClick import com.airbnb.mvrx.Fail import com.airbnb.mvrx.Success +import im.vector.matrix.android.api.failure.is401 import im.vector.riotx.R -import im.vector.riotx.core.error.is401 import kotlinx.android.synthetic.main.fragment_login_reset_password_mail_confirmation.* import javax.inject.Inject diff --git a/vector/src/main/java/im/vector/riotx/features/login/LoginWaitForEmailFragment.kt b/vector/src/main/java/im/vector/riotx/features/login/LoginWaitForEmailFragment.kt index 8a12c67106..c4507876d7 100644 --- a/vector/src/main/java/im/vector/riotx/features/login/LoginWaitForEmailFragment.kt +++ b/vector/src/main/java/im/vector/riotx/features/login/LoginWaitForEmailFragment.kt @@ -20,8 +20,8 @@ import android.os.Bundle import android.os.Parcelable import android.view.View import com.airbnb.mvrx.args +import im.vector.matrix.android.api.failure.is401 import im.vector.riotx.R -import im.vector.riotx.core.error.is401 import kotlinx.android.parcel.Parcelize import kotlinx.android.synthetic.main.fragment_login_wait_for_email.* import javax.inject.Inject