title: XMLHttpRequest detecting 404 (Not Found)
body: <p>If the URL is correct (file.dat exists), this works great (the file length matches).  If it is wrong I will see a very small file length and I will not see the <code>xhr.onerror</code>.</p>
  
  <p>How can I detect that the URL was incorrect?</p>
  
  <pre><code>var xhr = new XMLHttpRequest()
  xhr.responseType = "blob"
  xhr.onload = ()=&gt; {
      var reader = new FileReader()
      reader.onload = evt =&gt; {
          var contents = new Buffer(evt.target.result, 'binary')
          console.log('file len',contents.length) 
      }
      reader.readAsBinaryString(xhr.response)
  }
  xhr.addEventListener("error", () =&gt; { console.error('xhr.onerror',e) })
  xhr.open("GET", "file.dat")
  xhr.send()
  </code></pre>
  
  <p><a href="https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/Using_XMLHttpRequest" rel="noreferrer">https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/Using_XMLHttpRequest</a></p>
  
  <p>I do see a stacktrace in the console pointing to <code>xhr.send()</code>
  <code>GET http://localhost:8080/file.dat 404 (Not Found)</code></p>
  
  <p>A try catch around both open and send does not catch any exceptions.</p>
  
  <p>Files are served by WebpackDevServer (I hope that should not matter though).</p>