Response Parsing Error when Status Code is 204 (No Content)
还没有人认领这个 Issue。
评估
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 新手友好度
- 42/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 停滞
- 技术栈
- javascript
- 领域
- api
调研方向
从调用 resoptions.responseType || 'text' 然后调用 JSON.parse(data) 的响应处理代码段开始;在 Firefox 中复现一个返回状态 204 的 HTTP 请求。完成的标准是 204 响应不进行解析且不出现 JSON.parse 语法错误,同时其他响应保持现有行为。
由索引模型根据 Issue 内容生成。
描述
Problem:
Currently, the response from an HTTP request is being parsed, regardless of the status code. This behavior leads to the following error in the browser's debugger menu: "SyntaxError: JSON.parse: unexpected end of data at line 1 column 1 of the JSON data" when the status code is 204 (No Content). The error is triggered in Firefox.
Expected Behavior:
The parsing of the response data should only occur when the status code is not 204. When the status code is 204, the response should be left unparsed.
Steps to Reproduce:
- Perform an HTTP request that returns a status code of 204.
- Observe the error in the browser's debugger menu.
Code Segment:
return res[options.responseType || 'text']()
.then((data) => {
response.data = data;
// its okay if this fails: response.data will be the unparsed value:
response.data = JSON.parse(data);
})
.catch(Object)
.then(() => {
const ok = options.validateStatus ? options.validateStatus(res.status) : res.ok;
return ok ? response : Promise.reject(response);
});
Possible Solution:
To resolve this issue, you could modify the code to conditionally parse the response data based on the status code.
Additional Information:
- Browser/Environment:
Firefox - Redaxios Version:
0.5.1
- 主要语言
- JavaScript
- 星标
- 4.9k
- 派生
- 104
- PR 合并指标
- 30 天内没有已合并 PR
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
developit/redaxios 的其他 Issue
-
难度 3/5 1-2 天 新手友好度 45/100
-
难度 3/5 1-2 天 新手友好度 25/100
-
难度 3/5 1-2 天 新手友好度 35/100
-
难度 5/5 一周以上 新手友好度 20/100
-
难度 3/5 1-2 天 新手友好度 35/100
查看 developit/redaxios 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 82/100
-
area-deployment area-integrations triage:bot-seen
难度 2/5 半天 新手友好度 86/100
-
Issue-Bug
难度 2/5 1-3 小时 新手友好度 68/100
sugarlabs/musicblocks#8924 ·
-
难度 1/5 1 小时以内 新手友好度 90/100
ArduPilot/ardupilot_wiki#8088 ·
-
[BUG] createTool tools cannot be registered with Mastra when exactOptionalPropertyTypes is enabled 未关闭customer-eng status: needs triage
难度 2/5 1-3 小时 新手友好度 84/100