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

IE11 InvalidErrorStatus #64

Open
samuelms1 opened this issue Jul 21, 2016 · 2 comments
Open

IE11 InvalidErrorStatus #64

samuelms1 opened this issue Jul 21, 2016 · 2 comments

Comments

@samuelms1
Copy link

Using the browser-request module in IE11 causes an InvalidStateError to occur.

The request code looks like this:

var options = {
   url: "....",
   json: true,
   timeout: 2000
};
request.get(options, function(err, res, obj) {
   // Error occurs before here
});

I have a nodejs module that requires the "request" module which on the browser (via browserify) uses the browser-request module. I've mapped this module correlation in my package.json like this:

  "browser": {
    "request": "browser-request"
  }

Note that the request actually appears to work just fine, but IE logs an error

Here is a screenshot of the error in IE11 Developer Tools

image

@theopolisme
Copy link

Any updates on this? We're getting these errors too.

@samuelms1
Copy link
Author

I ended up writing a small shim for the request module that fit our very targeted needs (implemented the very minimum that we use from the request module). I would strongly prefer the browser-request module, but to get around this bug we used the shim (note that it assumes jquery is on the page as $).

module.exports = {
    get: function(options, callback){
        $.ajax({
            url: options.url,
            timeout: options.timeout,
            dataType: options.json === true ? 'json' : null,
            error: function(jqXHR, textStatus, errorThrown) {
                var errorMessage = "Error occurred while requesting " + options.url + ".";
                if (textStatus) {
                    errorMessage += "  Error status: " + textStatus;
                    if (errorThrown && errorThrown !== textStatus) {
                        errorMessage += " | Error Thrown: " + errorThrown;
                    }
                }
                var error = new Error(errorMessage);
                if (textStatus === 'timeout') {
                    error.code === 'ETIMEDOUT'
                } 
                error.status = jqXHR.status;
                callback(error);
            },
            success: function(data, textStatus, jqXHR){
                var responseObj = {
                    statusCode: jqXHR.status,
                    body: data
                };
                callback(null, responseObj, data);
            }
        });
    }
};

In package.json I added this:

{
  ...
  "browser": {
    "request": "./lib/browserRequestShim.js"
  }
  ...
}

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

2 participants