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

Network failures result in different `err` param passed to `onError`

Đang mở
#271 0 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
45/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, react
Lĩnh vực
frontend

Hướng nghiên cứu

Bắt đầu trong request.js, so sánh handler xhr.onerror với đường dẫn lỗi của xhr.onload và lệnh gọi getError được hiển thị trong issue. Tái hiện lần upload bị chặn trong ví dụ đơn giản, sau đó xác minh rằng các lỗi mạng truyền một lỗi cho onError với thông báo hiển thị cho người dùng nhất quán với các lỗi máy chủ.

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

Mô tả

Steps to reproduce

  1. Go to https://react-component.github.io/upload/examples/simple.html
  2. Upload a file
  3. Notice that as outlined in the example code
      onError(err) {
        console.log('onError', err);
      },

a error message is printed. This error message could be used to show some diagnostics to the user. The error message is assembled via this function in request.js

  xhr.onload = function onload() {
    // allow success when 2xx status
    // see https://github.com/react-component/upload/issues/34
    if (xhr.status < 200 || xhr.status >= 300) {
      return option.onError(getError(option, xhr), getBody(xhr));
    }

    return option.onSuccess(getBody(xhr), xhr);
  };

This is all well and correct.

  1. Now in the Network tab of DevTools right click on the previous upload.do request and Block it from the menu (to simulate a network failure).
  2. Upload a file - will be marked as Blocked in the Network tab.
  3. console.log(err) in onError now outputs a different error object without a message. This is totally different from the previous err parameter and not usable for printing to the user anymore

Looking at the stacktrace this code now comes from

  xhr.onerror = function error(e) {
    option.onError(e);
  };

also in request.js just above xhr.onload

Expected results

Network failures should also pass the same err object to the onError prop as there would be a server message failure, so that it is easier to show such errors to the user.

Ngôn ngữ chính
TypeScript
Star
804
Fork
323
Merge trung bình
12 phút
Pull request đã merge (30 ngày)
1

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

Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.

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 react-component/upload

Tất cả issue của react-component/upload

Issue tương tự

Thêm issue về TypeScript

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.