Response Parsing Error when Status Code is 204 (No Content)
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:
- 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
- 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
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- 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.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của developit/redaxios
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 45/100
-
Mock redaxios with vi.mock()Đang mở
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 25/100
-
Does redaxios support adaptor?Đang mở
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 35/100
-
State of the project ?Đang mở
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 20/100
-
add next and cache supportĐang mở
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 35/100
Tất cả issue của developit/redaxios
Issue tương tự
-
bug good first issue
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 86/100
amponce/archive-movie-browser#354 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
saayam-for-all/webapp#1870 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
Imageomics/OpenCite#66 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 64/100
chr15m/twiiit.com#20 ·
-
documentation
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
antropos17/Aegis#629 ·
Maintainer thường phản hồi trong vòng 4 ngày