Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

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

Đang mở
#96 1 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
42/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
javascript
Lĩnh vực
api

Hướng nghiên cứu

Bắt đầu với đoạn mã xử lý phản hồi gọi resoptions.responseType || 'text' rồi JSON.parse(data); tái hiện trong Firefox một yêu cầu HTTP trả về trạng thái 204. Hoàn thành khi phản hồi 204 không được phân tích cú pháp và không xuất hiện lỗi cú pháp JSON.parse, trong khi các phản hồi khác vẫn giữ nguyên hành vi hiện có.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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
Ngôn ngữ chính
JavaScript
Star
4.9k
Fork
104
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của developit/redaxios

Tất cả issue của developit/redaxios

Issue tương tự

Thêm issue về JavaScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.