From 8bcbbe8dfa4ec96912d4b7030c51241268d1e1e2 Mon Sep 17 00:00:00 2001 From: HuanCheng65 <22636177+HuanCheng65@users.noreply.github.com> Date: Sat, 11 Mar 2023 00:02:32 +0800 Subject: [PATCH] =?UTF-8?q?pref:=20=E6=9C=AA=E7=99=BB=E5=BD=95=E5=BC=82?= =?UTF-8?q?=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../post/api/retrofit/exception/TiebaLocalException.kt | 2 +- .../api/retrofit/exception/TiebaNotLoggedInException.kt | 7 +++++++ .../api/retrofit/interceptors/ForceLoginInterceptor.kt | 5 ++--- 3 files changed, 10 insertions(+), 4 deletions(-) create mode 100644 app/src/main/java/com/huanchengfly/tieba/post/api/retrofit/exception/TiebaNotLoggedInException.kt diff --git a/app/src/main/java/com/huanchengfly/tieba/post/api/retrofit/exception/TiebaLocalException.kt b/app/src/main/java/com/huanchengfly/tieba/post/api/retrofit/exception/TiebaLocalException.kt index d9553323..f6400ffd 100644 --- a/app/src/main/java/com/huanchengfly/tieba/post/api/retrofit/exception/TiebaLocalException.kt +++ b/app/src/main/java/com/huanchengfly/tieba/post/api/retrofit/exception/TiebaLocalException.kt @@ -1,6 +1,6 @@ package com.huanchengfly.tieba.post.api.retrofit.exception -class TiebaLocalException( +open class TiebaLocalException( override val code: Int, msg: String ) : TiebaException(msg) \ No newline at end of file diff --git a/app/src/main/java/com/huanchengfly/tieba/post/api/retrofit/exception/TiebaNotLoggedInException.kt b/app/src/main/java/com/huanchengfly/tieba/post/api/retrofit/exception/TiebaNotLoggedInException.kt new file mode 100644 index 00000000..5bad528c --- /dev/null +++ b/app/src/main/java/com/huanchengfly/tieba/post/api/retrofit/exception/TiebaNotLoggedInException.kt @@ -0,0 +1,7 @@ +package com.huanchengfly.tieba.post.api.retrofit.exception + +import com.huanchengfly.tieba.post.api.Error.ERROR_NOT_LOGGED_IN + +class TiebaNotLoggedInException( + msg: String = "Not logged in!" +) : TiebaLocalException(ERROR_NOT_LOGGED_IN, msg) \ No newline at end of file diff --git a/app/src/main/java/com/huanchengfly/tieba/post/api/retrofit/interceptors/ForceLoginInterceptor.kt b/app/src/main/java/com/huanchengfly/tieba/post/api/retrofit/interceptors/ForceLoginInterceptor.kt index 7d763ec0..ad9a2308 100644 --- a/app/src/main/java/com/huanchengfly/tieba/post/api/retrofit/interceptors/ForceLoginInterceptor.kt +++ b/app/src/main/java/com/huanchengfly/tieba/post/api/retrofit/interceptors/ForceLoginInterceptor.kt @@ -1,8 +1,7 @@ package com.huanchengfly.tieba.post.api.retrofit.interceptors -import com.huanchengfly.tieba.post.api.Error.ERROR_NOT_LOGGED_IN import com.huanchengfly.tieba.post.api.Header -import com.huanchengfly.tieba.post.api.retrofit.exception.TiebaLocalException +import com.huanchengfly.tieba.post.api.retrofit.exception.TiebaNotLoggedInException import com.huanchengfly.tieba.post.utils.AccountUtil import okhttp3.Interceptor import okhttp3.Response @@ -23,7 +22,7 @@ object ForceLoginInterceptor : Interceptor { } if (forceLogin && !AccountUtil.isLoggedIn()) { - throw TiebaLocalException(ERROR_NOT_LOGGED_IN, "Not logged in.") + throw TiebaNotLoggedInException() } return chain.proceed(