美文网首页
flutter Dio formatError

flutter Dio formatError

作者: 一个半吊子工程师 | 来源:发表于2020-07-20 14:05 被阅读0次
/*
   * error统一处理
   */
  void formatError(Function errorCallBack, DioError e) {
    if (e.type == DioErrorType.CONNECT_TIMEOUT) {
      // It occurs when url is opened timeout.
      errorCallBack("连接超时");
//      showToast("连接超时");
    } else if (e.type == DioErrorType.SEND_TIMEOUT) {
      // It occurs when url is sent timeout.
      errorCallBack("请求超时");
//      showToast("请求超时");
    } else if (e.type == DioErrorType.RECEIVE_TIMEOUT) {
      //It occurs when receiving timeout
      errorCallBack("响应超时");
//      showToast("响应超时");
    } else if (e.type == DioErrorType.RESPONSE) {
      // When the server response, but with a incorrect status, such as 404, 503...
      errorCallBack("响应异常");
//      showToast("响应异常");
    } else if (e.type == DioErrorType.CANCEL) {
      // When the request is cancelled, dio will throw a error with this type.
      errorCallBack("请求取消");
//      showToast("请求取消");
    } else {
      //DEFAULT Default error type, Some other Error. In this case, you can read the DioError.error if it is not null.
      errorCallBack("未知错误");
//      showToast("未知错误");
    }
  }

相关文章

网友评论

      本文标题:flutter Dio formatError

      本文链接:https://www.haomeiwen.com/subject/zqaekktx.html