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

onerror function does not receive an error as an argument #162

Open
uladkasach opened this issue Mar 10, 2018 · 0 comments
Open

onerror function does not receive an error as an argument #162

uladkasach opened this issue Mar 10, 2018 · 0 comments

Comments

@uladkasach
Copy link

This issue can be recreated quite simply:

        return new Promise((resolve, reject)=>{
            var xhr = new XMLHttpRequest();
            //xhr.overrideMimeType("application/json");
            xhr.open("GET", "test", true);
            xhr.onload = function(){
                console.log(this.responseText);
                resolve(this.responseText);
            };
            xhr.onerror = function(error){
                console.log(this);
                throw (error);
            };
            xhr.send();
        })

Although the onerror function is triggered, the error object is undefined.

This is strange since the output of console.log(this) in the above code snippet demonstrates that the reason for the error is clearly known. The output is the following:

{ UNSENT: 0,
  OPENED: 1,
  HEADERS_RECEIVED: 2,
  LOADING: 3,
  DONE: 4,
  readyState: 4,
  onreadystatechange: null,
  responseText: 'Error: connect ECONNREFUSED 127.0.0.1:80\n    at Object.exports._errnoException (util.js:1022:11)\n    at exports._exceptionWithHostPort (util.js:1045:20)\n    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1146:14)',
  responseXML: '',
  status: 0,
  statusText: 
   { Error: connect ECONNREFUSED 127.0.0.1:80
       at Object.exports._errnoException (util.js:1022:11)
       at exports._exceptionWithHostPort (util.js:1045:20)
       at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1146:14)
     code: 'ECONNREFUSED',
     errno: 'ECONNREFUSED',
     syscall: 'connect',
     address: '127.0.0.1',
     port: 80 },
  withCredentials: false,
  open: [Function],
  setDisableHeaderCheck: [Function],
  setRequestHeader: [Function],
  getResponseHeader: [Function],
  getAllResponseHeaders: [Function],
  getRequestHeader: [Function],
  send: [Function],
  handleError: [Function],
  abort: [Function],
  addEventListener: [Function],
  removeEventListener: [Function],
  dispatchEvent: [Function],
  onload: [Function],
  onerror: [Function] }
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