How to catch NetworkError in JavaScript?

前端 未结 4 643
失恋的感觉
失恋的感觉 2021-02-07 01:30

In Chrome\'s JavaScript console, if I run this:

var that = new XMLHttpRequest();
that.open(\'GET\', \'http://this_is_a_bad_url.com\', false);
that.send();
         


        
4条回答
  •  花落未央
    2021-02-07 01:48

    exception.name returns 'Error' even on network errors a better way can be checking if error has url config like this :

    if(exception.config && exception.config.url){
      // network error
    } else {
      // other errors
    }
    

提交回复
热议问题