Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Network failures result in different err param passed to onError #271

Open
jnachtigall opened this issue Aug 25, 2020 · 0 comments
Open

Comments

@jnachtigall
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant