If ajax observable has parameter timeout configured, with a slow request, ajax is emitting a next instead of an error.
RxJS version:
6.0.0
Code to reproduce:
ajax({
url: 'https://reqres.in/api/users?delay=5',
timeout: 500,
}).subscribe({
next: v => console.log('next', v),
error: err => console.log('err', err),
});
Expected behavior:
Emit an error event with an AjaxError object
Actual behavior:
Emit a next event with ajax null response and status 0
This bug prevents me from catching errors when a user makes an XHR request with a downed network, independent of a timeout value being set.
Workaround:
tap(response => {
if (response.status === 0) {
throw Object.assign(new Error('Ajax status 0'), response)
}
}),
I believe #3653 also fixes the issue with down network: moving the next() logic from onreadystatechange to onload allows onerror to trigger first.
@bbonnet Was this fixed by https://github.com/ReactiveX/rxjs/pull/3653?
Tested and working on 6.4.*
In which version was this actually fixed?
Most helpful comment
Workaround: