# request-error **Repository Path**: luli1314520/request-error ## Basic Information - **Project Name**: request-error - **Description**: No description available - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2025-11-13 - **Last Updated**: 2025-11-13 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # 并发分片请求示例 该示例演示如何通过 `Promise.all`/`Promise.allSettled` 并发请求多个文本分片,并在出现网络失败时进行重试与结果兜底。项目包含一个模拟 TTS 的后端和一个展示前端。 ## 目录结构 - `backend`:Node.js + Express 模拟 TTS 服务,随机返回成功或失败 - `frontend`:浏览器端静态页面,拆分文本并发请求,处理失败重试 ## 快速开始 1. 安装后端依赖 ```bash cd backend npm install npm run start ``` 服务默认监听 `http://localhost:3000`。 2. 启动前端 直接用浏览器打开 `frontend/index.html` 即可(也可以使用任意本地静态服务器,例如 `npx serve frontend`)。 3. 在页面中输入文本,点击“转换”。前端会: - 将长文本按固定长度拆分 - 使用 `Promise.all` 并发请求所有分片 - 结合 `Promise.allSettled` 与自定义 `fetchWithRetry`,对失败的请求进行重试 - 最终展示成功与失败的分片列表 ## 关键点 - `Promise.allSettled` 保证即便部分失败也能收集全部结果 - 指数退避重试策略应对临时网络波动 - 分片大小可根据服务端限制和 TTS 精度调整 > 如需对接真实 TTS 服务,可在 `backend/server.js` 中替换 `simulateTtsProcessing`,并在前端将模拟的文本 Blob 替换为真实音频数据。