title: How to catch Chrome error net::ERR_FILE_NOT_FOUND in XMLHttpRequest?
body: <p>I want to create chrome extension which will be able to read local files and use code wrote in them. My simplyfied code is:</p>
  
  <pre><code>const readFile = (filePath) =&gt; {
    return new Promise(function (resolve, reject) {
      const xhr = new XMLHttpRequest()
      xhr.onerror = (error) =&gt; {
        reject(error)
      }
      xhr.onreadystatechange = function () {
        if (xhr.readyState === 4) {
          resolve(xhr.response)
        }
      }
      xhr.ontimeout = function () {
        reject('timeout')
      }
      xhr.open('GET', filePath)
      xhr.send()
    })
  }
  
  async function () {
      const code = await readFile(jsFilePath)
      console.log(code)
  }
  </code></pre>
  
  <p>This code successfully works when my filePath is correct. But when it is not Chrome console throws this error:</p>
  
  <pre><code>GET file:///home/maxim/Documents/test.jsa net::ERR_FILE_NOT_FOUND
  </code></pre>
  
  <p>Usual try/catch block doesn't work</p>
  
  <pre><code>async function () {
    try {
      const code = await readFile(jsFilePath)
      console.log(code)
    } catch (e) {
      console.log(e)
    }
  }
  </code></pre>
  
  <p>How can I catch this type of errors? </p>