As mentioned in the comments, onerror
fires when there is a failure on the network level. If the error only exists on the application level, e.g., an HTTP error code is sent, then onload
still fires. You need to test the returned status code explicitly in your onreadystatechange
handler.
Note that a denied cross-domain request will also fire the onerror
handler.