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

Observable.ajax error 0 #1926

Closed
blakef opened this issue Sep 8, 2016 · 16 comments
Closed

Observable.ajax error 0 #1926

blakef opened this issue Sep 8, 2016 · 16 comments

Comments

@blakef
Copy link
Contributor

blakef commented Sep 8, 2016

RxJS version:
5.0.0-beta.11

Code to reproduce:

const notService = 1234
Rx.Observable
  .ajax(`http://localhost:${notService}/foo`)
  .subscribe(x => {}, err => console.log('Err:', err.message))
;

Expected behavior:
Output: Err: ajax network error

Actual behavior:
Output: Err: ajax error 0

Additional information:
At the moment if you encounter a network error, the xhr spec requires a response with status 0.

I'd argue that the error message is opaque, and we should look use the text 'network error' in place of just 'status 0' in the AjaxError.

Thoughts?

@jayphelps
Copy link
Member

I think ajax error 0 is fine because it's consistent. Any errors have the same message format, ajax error <status>. AFAIK a zero status code could mean more than a network error and we don't really have a great way of knowing which one it is.

  • User started to leave the page, so it was aborted by the browser
  • Timeout
  • Network errors

Basically it's set to zero to start with, and doesn't change until it gets an HTTP status code back from the response.

@blakef
Copy link
Contributor Author

blakef commented Sep 11, 2016

It's not unreasonable to argue that my reading of the error message was naive, expecting an HTTP error code and getting a 0 instead (and being confused by it).

@jayphelps you've made a reasonable case for sticking with 0.

@blakef blakef closed this as completed Sep 11, 2016
@iansinnott
Copy link

I notice that the original error object is also discarded. Is there any way we could improve the ajax error handling to give more context into these errors? I'd be happy to PR something but not sure what best approach would be. The only thing that came to mind is passing the original XHR error through.

@OliverJAsh
Copy link
Contributor

The only thing that came to mind is passing the original XHR error through.

Agreed. In the case of a network error, the observable will emit an error from onreadystatechange instead of the original XHR error in onerror.

A 0 status code doesn't just imply a network error but many other things: https://stackoverflow.com/a/26451773/5932012

Therefore I don't see any reliable way to infer whether an error was caused by a network error or something else.

@stiofand
Copy link

stiofand commented Dec 4, 2017

There appears to be bigger issues with the latest ajax functionality, but nothing is truly being addressed. IN fact the docs for the latest api show an example that fails , yet no one has addressed the issue, despite many issue reports. I love rxjs observable but the lack of consistency is creating a situation where our project will soon be dropping it.

One issue I have (which is pretty glaring considering the behaviours of similar libraries) is the apparent inability to handle simple get requests with parameters. If there is such an ability, the documentation, examples and offered solutions somehow manage to completely be absent of this base functionality.

For exampe, the following using rxjs with react-redux (redux-observable) implements Observable ajax, exampes are tried with ajax() and ajax.get()

/* FAILS */
.....
Observable
                .ajax('http://localhost:3001/login') // note in this iteration no params
                .map((loginResponse) => ... do things with response

/ * FAILS */
Observable
                .ajax('http://localhost:3001/login?/user=###&password=####') 
                .map((loginResponse) => ... do things with response

/ * FAILS */
Observable
                .ajax('http://localhost:3001/login', params) // params is an object here
                .map((loginResponse) => ... do things with response

/* Using standard fetch */
/* PASSES */
Observable
                .fetch('http://localhost:3001/login', params) // params is an object here
                .map((loginResponse) => Observable.of(loginResponse)

All also work using jQuery, request and axios to make the same requests.

So am I missing something glaringly obvious, or is there a real issue which no one wants to look into here??

In each case, the back end isnt' even touched (in this case a simple express server) but with the other libraries everything works as it should.

@jayphelps
Copy link
Member

I don’t enjoy people threatening to stop using things I make. It’s free software that I do in my personal time and don’t get a single cent for. Being abusive just makes me to want to help even less.

@stiofand
Copy link

stiofand commented Dec 4, 2017

I am sorry you thought it a threat, it was certainly never intended as such. It was simply an observation and personal opinion. Of course there is a degree of frustration, and the library is generally appreciated. However it is not anything personal, I do not partake in such things.

@stiofand
Copy link

stiofand commented Dec 4, 2017

@jayphelps, please do not take such criticism as abuse, I can't really see how it could have been construed as such, but I apologise if that's how you took it.

@stiofand
Copy link

stiofand commented Dec 4, 2017

I also fully admit it could well be my misunderstanding of the API / docs, I'd if so, I gladly hold my hands up as the guilty party

@jayphelps
Copy link
Member

jayphelps commented Dec 4, 2017

clarification: I thought this conversation was on redux-observable’s issue tracker as you commented there as well and I mixed them up redux-observable/redux-observable#84 (comment). So my statements here aren’t entirely applicable as rxjs is much more of a community project and I left the core team a while ago (time constraints). They do not necessarily reflect the opinions of the core team and I’m sorry for confusing the two. My thoughts still apply to your comments in redux-observable.

As a fellow community member I still think such repeated comments are abusive and counterproductive. I can’t express how demotivating it is.


There appears to be bigger issues with the latest ajax functionality, but nothing is truly being addressed. IN fact the docs for the latest api show an example that fails , yet no one has addressed the issue, despite many issue reports. I love rxjs observable but the lack of consistency is creating a situation where our project will soon be dropping it. #1926 (comment)

The lack of clear examples for the latest version api is making it problematic to say the least. Tests and outdated documentation mean that its always a struggle to find any solutions. javorka is correct, there is a range of issues with ajax, yet there is no solution or example offered. It has got to the stage where we are considering dropping the use of Observable ajax in favour of a more well documented library. #2139 (comment)

Probably going to avoid epics this way until some kind soul can provide documentation or examples. redux-observable/redux-observable#84 (comment)

@aranda-adapptor
Copy link

I'm also getting this error and now wondering whether URL parameters are supported in rxjs' ajaxGet function. I can't seem to find any examples of it.

@OliverJAsh
Copy link
Contributor

@aranda-adapptor AFAIK you have to append them yourself to the URL.

@iansinnott
Copy link

@aranda-adapptor yup, as mentioned above you need to construct the query string yourself. This is pretty trivial though since there are a number of libraries to do this, including the built in querystring which is what I use with rxjs: querystring docs.

@aranda-adapptor
Copy link

@OliverJAsh @iansinnott I am indeed appending them (just using string interpolation) and still getting this error. Reading the comments above implied that it may not be supported. Thanks for clarifying that it is supported. I guess my issue lies elsewhere!

@jayphelps
Copy link
Member

jayphelps commented Jan 31, 2018

@aranda-adapptor Try Chrome Dev Tools. It should say in the console why the XMLHttpRequest was refused. 👍 Just keep in mind that status code zero can mean many things nearly all of which cannot be known programmatically. Only in the dev tools

@lock
Copy link

lock bot commented Jun 6, 2018

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Jun 6, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants