Albert Nemec
Albert Nemec

Reputation: 801

RxJs - Ajax error 0 instead of 502 occurres

I'm using RxJS 6 and it's ajax module to fetch data. After getting 502 from my API, I expect status of the response object pasted below would be 502. However the status is 0.

From all kinds of issues, I understand status 0 is the default status for all response object generated from RxJS.ajax and after response is received the status value is overwritten to the one that the server provides.

Here, clearly the server provides status code 502, but the status in the response object is still 0.

response

Have you encountered this behaviour? Is there a fix/workaround? Or is it legitimate bug in the library, and I should post it to their issue tracker?

Upvotes: 1

Views: 419

Answers (1)

Albert Nemec
Albert Nemec

Reputation: 801

Figured it out.

When the API falls on 5xx, our server fails to provide appropriate CORS header back to the browser in OPTIONS response.

This prevents Javascript from successfully overwrite the response object and error with status 0 is catched.

It should be handled on server side, or client can infer that status 0 should be handled as status 5xx. (that is however bit hacky, as status 0 normally refers to things like network outage).

Upvotes: 1

Related Questions