Flotype / now

NowJS makes it easy to build real-time web apps using JavaScript
http://www.nowjs.com
MIT License
1.91k stars 175 forks source link

connection related errors on client call (errback needed?) #99

Closed jcham closed 13 years ago

jcham commented 13 years ago

Sorry if I'm missing this documented somewhere obvious, but what is the proper way for client calls to handle connection errors? Obviously an errback in the parameters wouldn't work.

For example, this would seem to be a common pattern:

now.gimmeStuff(function(stuff) {
  // do something with stuff
})

but if the network or server were down, how would the client code know about it. Is the only way to listen to the (global) 'disconnect' event?

What'd be great would be something like:

now.gimmeStuff(function(stuff) {
  // do something with stuff
}).onError(function(err) {
  // oops, alert user
})
ericz commented 13 years ago

Hi jcham,

This isn't implemented yet. The problem is if we provided an errback then we'd be breaking expected behaviors as there would be an implicit argument for the callback. In the future we don't want exceptions thrown on the server-side due to client activity to disconnect the client (as it does now) and thus trigger a disconnect event on the client-side. When we have fixed that issue then indeed there will be a .on('error', func(){} ) event. However that event would probably still be global.

ericz commented 13 years ago

We've decided not to have an errback for function calls or variable syncing as we don't have the facilities to provide accurate error information. However there are events emitted for failed connects or server disconnected in 0.7 as documented here:

http://www.nowjs.com/doc/now

Thanks for the report jcham, closing.