Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ajax response with status 0 must throw an error #3606

Closed
eltiodelsofa opened this issue Apr 26, 2018 · 7 comments
Closed

Ajax response with status 0 must throw an error #3606

eltiodelsofa opened this issue Apr 26, 2018 · 7 comments
Labels
bug Confirmed bug

Comments

@eltiodelsofa
Copy link

eltiodelsofa commented Apr 26, 2018

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

@benlesh benlesh added the bug Confirmed bug label Apr 26, 2018
@bgerm
Copy link

bgerm commented May 8, 2018

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.

@felixfbecker
Copy link
Contributor

Workaround:

tap(response => {
            if (response.status === 0) {
                throw Object.assign(new Error('Ajax status 0'), response)
            }
        }),

@adriensamson
Copy link

I believe #3653 also fixes the issue with down network: moving the next() logic from onreadystatechange to onload allows onerror to trigger first.

@felixfbecker
Copy link
Contributor

@bbonnet Was this fixed by #3653?

@goenning
Copy link

goenning commented May 2, 2019

Tested and working on 6.4.*

rxjs-ajax

@ndlarsen
Copy link

In which version was this actually fixed?

@cartant
Copy link
Collaborator

cartant commented May 1, 2021

Closed by #3653

@cartant cartant closed this as completed May 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Confirmed bug
Projects
None yet
Development

No branches or pull requests

8 participants