I think you could use the same callback for ontimeout and onerror:

```javascript
xhr.ontimeout = xhr.onerror = function onerror(evt) {
 // use evt.type if you want to display which event it is
}
```