Skip to content

bug(inula-request): blob 下载开始后断网未进入 catch 导致弹框卡住 #65

@HoikanChan

Description

@HoikanChan

This was generated by AI during triage.

Bug 描述

packages/inula-request 中使用 axios.request 下载 blob 响应时,如果下载已经开始后网络中断,请求不会进入 catch,导致下载弹框一直卡在下载中状态,无法弹出错误提示。

复现代码

axios.request({
  url,
  method: 'get',
  params: {
    taskId: paramValue,
  },
  responseType: 'blob',
  headers: { ...exportInstanceHeader.getInstanceHeader() },
  onDownloadProgress: progressRes => {
    if (progressRes) {
      const { loaded, total } = progressRes;
      const percentage = parseInt(loaded / total * FULLFIELD_PROGRESS, 10);
      dispatch({
        type: types.DOWNLOAD_RES,
        payload: {
          currentDownloadProgress: Number.isNaN(percentage) ? 0 : percentage,
        },
      });
    }
  },
}).then(response => {
  dispatch({
    type: types.DOWNLOAD_RES,
    payload: {
      isDownloading: false,
      currentDownloadProgress: FULLFIELD_PROGRESS,
    },
  });

  const blob = new Blob(
    [response.data],
    { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8' },
  );
  const filename = response.headers['content-disposition'].split(';')[1].split('=')[1];
  const href = window.URL.createObjectURL(blob);

  if (window.navigator.msSaveBlob) {
    window.navigator.msSaveBlob(blob, filename);
  } else {
    const aEle = document.createElement('a');
    aEle.href = href;
    aEle.download = filename;
    document.body.appendChild(aEle);
    aEle.click();
    document.body.removeChild(aEle);
  }

  window.URL.revokeObjectURL(href);
}).catch(error => {
  dispatch({
    type: types.DOWNLOAD_RES,
    payload: {
      isDownloading: false,
    },
  });
  exportBlobErrorHandler(error, err => CommonMessageDialog.getInstance().openExceptionDialog(err.response));
});

复现步骤

  1. 触发导出流程。
  2. 点击确定进行导出,等待导出任务完成,进入待下载界面。
  3. 限制网络速度。
  4. 点击确定开始下载。
  5. 请求开始出现下载进度后断开网络。
  6. 观察下载弹框状态。

期望行为

下载过程中断网后,请求应进入 catch

  • isDownloading 置为 false
  • 调用错误处理逻辑;
  • 弹出报错框提示用户下载失败。

实际行为

下载已经开始后断网,请求没有进入 catch,下载弹框一直卡住。

影响范围

  • 影响 responseType: 'blob' 的文件下载场景。
  • 用户在弱网或下载过程中网络中断时无法感知失败,也无法正常结束下载状态。

备注

疑似与下载进度事件触发后,网络中断没有正确 reject 请求有关。建议排查 packages/inula-request 对 XHR/axios 适配层中 progresserroraborttimeout 等事件的处理逻辑。

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions