| | |
| | | import android.graphics.Bitmap; |
| | | import android.util.Log; |
| | | |
| | | import com.driver.igotrip.R; |
| | | import com.driver.igotrip.base.BaseEvent; |
| | | import com.driver.igotrip.base.MyApplication; |
| | | import com.driver.igotrip.ui.pub.LoginActivity; |
| | |
| | | import cn.sinata.rxnetty.NettyClient; |
| | | import cn.sinata.xldutils.activitys.BaseActivity; |
| | | import cn.sinata.xldutils.fragment.BaseFragment; |
| | | import cn.sinata.xldutils.net.utils.Error; |
| | | import cn.sinata.xldutils.net.utils.ResultException; |
| | | import cn.sinata.xldutils.utils.StringUtils; |
| | | import cn.sinata.xldutils.utils.Toast; |
| | |
| | | WeakReference<BaseActivity> activities; |
| | | WeakReference<BaseFragment> fragments; |
| | | Context context; |
| | | |
| | | public static final String REQUEST_ERROR = "请求出错!"; |
| | | public static final String PARSER_ERROR = "数据解析出错!"; |
| | | public static final String SERVER_ERROR = "服务器异常,请稍后重试!"; |
| | | public static final String NET_ERROR = "未连接到服务器!"; |
| | | public static final String NET_TIMEOUT = "链接超时,请稍后再试!"; |
| | | |
| | | |
| | | public MyNoMsgObserver(BaseActivity activity) { |
| | | activities = new WeakReference<>(activity); |
| | |
| | | LogUtils.e("responseString", "**" + responseString); |
| | | if (StringUtils.isEmpty(responseString)) { //判空 |
| | | int code = -1; |
| | | String msg = PARSER_ERROR; |
| | | String msg = getShowErrorMsg(Error.PARSER_ERROR); |
| | | onError(code, msg, responseString); |
| | | return; |
| | | } |
| | |
| | | Utils.systemErr(e); |
| | | Log.e("responseString", "responseString get " + e.toString()); |
| | | int code = -1; |
| | | String msg = context.getString(R.string.请求出错); |
| | | String msg = getShowErrorMsg(Error.REQUEST_ERROR); |
| | | if (e instanceof JsonSyntaxException || |
| | | e instanceof NumberFormatException || |
| | | e instanceof IllegalStateException) { |
| | | msg = PARSER_ERROR; |
| | | msg = getShowErrorMsg(Error.PARSER_ERROR); |
| | | } else if (e instanceof HttpException) { |
| | | msg = SERVER_ERROR; |
| | | msg = getShowErrorMsg(Error.SERVER_ERROR); |
| | | } else if (e instanceof ConnectException) { |
| | | msg = NET_ERROR; |
| | | msg = getShowErrorMsg(Error.NET_ERROR); |
| | | } else if (e instanceof SocketTimeoutException) { |
| | | msg = NET_TIMEOUT; |
| | | msg = getShowErrorMsg(Error.NET_TIMEOUT); |
| | | } else if (e instanceof ResultException) { |
| | | code = ((ResultException) e).getCode(); |
| | | msg = e.getMessage(); |
| | |
| | | |
| | | protected void onError(int code, String msg, String resposeString) { |
| | | if (shouldShowErrorToast()) { |
| | | Log.e( "onError: ", "长连接请求报错"+msg); |
| | | // showToast(msg); |
| | | Log.e("onError: ", "长连接请求报错" + msg); |
| | | // showToast(msg); |
| | | } |
| | | } |
| | | |
| | |
| | | public void dispose() { |
| | | |
| | | } |
| | | |
| | | /** |
| | | * 获取异常显示信息 |
| | | */ |
| | | public String getShowErrorMsg(Error error) { |
| | | int typeByLanguage = HttpManager.getTypeByLanguage(); |
| | | return switch (typeByLanguage) { |
| | | case 3 -> error.getErrorFr(); |
| | | case 1 -> error.getErrorCh(); |
| | | default -> error.getErrorEn(); |
| | | }; |
| | | } |
| | | } |