createErrorEntity method

ErrorRes createErrorEntity(
  1. DioError? error
)

Implementation

ErrorRes createErrorEntity(DioError? error) {
  switch (error?.type) {
    case DioErrorType.cancel:
      {
        return ErrorRes(code: -1, message: "请求取消");
      }
    case DioErrorType.connectTimeout:
      {
        return ErrorRes(code: -1, message: "连接超时");
      }
    case DioErrorType.sendTimeout:
      {
        return ErrorRes(code: -1, message: "请求超时");
      }
    case DioErrorType.receiveTimeout:
      {
        return ErrorRes(code: -1, message: "响应超时");
      }
    case DioErrorType.response:
      {
        try {
          int? errCode = error?.response?.statusCode;
          String? errMsg = error?.response?.statusMessage;
          return ErrorRes(code: errCode, message: errMsg);
        } on Exception catch (_) {
          return ErrorRes(code: -1, message: "未知错误");
        }
      }
    default:
      {
        return ErrorRes(code: -1, message: error?.message);
      }
  }
}