Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

Response Parsing Error when Status Code is 204 (No Content)

未关闭
#96 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 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:

  1. Perform an HTTP request that returns a status code of 204.
  2. 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

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

developit/redaxios 的其他 Issue

查看 developit/redaxios 的全部 Issue

相似的 Issue

更多 JavaScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。