handleErrorStatus function

void handleErrorStatus(
  1. Response response
)

Implementation

void handleErrorStatus(Response response) async {
  bool isOk = await isConnected();
  if (!isOk) {
    Alert.showAlert('网路错误,请检查当前网络');
    return;
  }
  Loading.dismiss();
  switch (response.statusCode.toString()) {
    case ConstValue.code400:
      {
        if (response.body is Map) {
          Map<String, dynamic> bodyMap = response.body as Map<String, dynamic>;
          String msg = bodyMap['message'] ?? '';
          if (msg.isBlank == false) {
            if (msg.contains('/body/xml/auth_code') ||
                msg.contains('字符串规则校验失败')) {
              Alert.showAlert('请确认扫一扫为微信码');
            } else if (msg.contains('支付异常')) {
              Alert.showAlert('支付失败');
            } else if (msg.contains('版本不存在!') || msg.contains('app名称不存在!')) {
              break;
            } else {
              if (response.request != null &&
                  response.request.isBlank == false) {
                bool isNeedAlert = handleRspAlert(response.request!);
                if (isNeedAlert) {
                  String rspAlertStr = handleRspAlertStr(response.request!);
                  if (rspAlertStr.isBlank == false) {
                    Alert.showAlert(rspAlertStr);
                  } else {
                    Alert.showAlert(bodyMap['message'] ?? '');
                  }
                }
              }
            }
          }
        }
      }
      break;
    case ConstValue.code500:
      Alert.showAlert('服务器异常,请稍后再试');
      break;
    case ConstValue.code403:
      Toast.showText('登录已失效,请重新登录');
      AuthService.to.logOut();
      StorageService.instance.remove(StorageValue.userToken);
      Get.offNamedUntil(Routes.login, (route) => false);
      break;
    default:
  }
  return;
}