|
@@ -0,0 +1,46 @@
|
|
|
+package com.cooleshow.base.utils.helper;
|
|
|
+
|
|
|
+import com.alibaba.android.arouter.launcher.ARouter;
|
|
|
+import com.cooleshow.base.data.net.ApiException;
|
|
|
+import com.cooleshow.base.router.RouterPath;
|
|
|
+import com.cooleshow.base.utils.ToastUtils;
|
|
|
+
|
|
|
+/**
|
|
|
+ * Author by pq, Date on 2022/5/9.
|
|
|
+ */
|
|
|
+public class ErrorParse {
|
|
|
+ private static volatile ErrorParse mErrorParse;
|
|
|
+ public static int TOKEN_INVALID_ERROR_CODE = 403;//token异常
|
|
|
+
|
|
|
+ private ErrorParse() {
|
|
|
+ }
|
|
|
+
|
|
|
+ public static ErrorParse getInstance() {
|
|
|
+ if (mErrorParse == null) {
|
|
|
+ synchronized (ErrorParse.class) {
|
|
|
+ if (mErrorParse == null) {
|
|
|
+ mErrorParse = new ErrorParse();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return mErrorParse;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void parseError(Throwable throwable) {
|
|
|
+ if (throwable instanceof ApiException) {
|
|
|
+ ApiException apiException = (ApiException) throwable;
|
|
|
+ ToastUtils.showShort("onError:" + apiException.getErrmsg());
|
|
|
+ if (apiException.getErrcode() == TOKEN_INVALID_ERROR_CODE) {
|
|
|
+ logOut();
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ throwable.printStackTrace();
|
|
|
+ ToastUtils.showShort("未知错误");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void logOut() {
|
|
|
+ ARouter.getInstance().build(RouterPath.UserCenter.PATH_VERIFY_LOGIN).navigation();
|
|
|
+ }
|
|
|
+}
|