ember.js - Handling network connectivity and promise rejections in Ember -


I am trying to implement an application-level error handler to catch unsuccessful promises in my application. The suggestions I have seen around this have to do with error logging, but I really want to trigger a model window so that my users can know that they are no longer connected to the internet + just read data You can.

I RSVP The only way I have managed to do this is to: Start the attacker inside the panic handler, in this way:

  Amber. RSVP. Configure ('panic', function (e) {window.App.__container__.lookup ('Controller: Application'). Send ('showdown', 'disconnect');});  

But it seems a bit hack for me.

Is writing this code more suitable? More generally, is there a best practice to inform users of lost internet connections?

Amber has a built-in.

Depending on the type of errors in your app, you can add view / error.js and depending on how you want to manage it, and in that view, willInsertElement < / Code> can run a method that is whether or not the user is offline, and if true, send the showModal operation

Alternatively, unsuccessful promise can be caught in the original promise by itself and some such method is triggered which is injected into the controller or whatever promises:

Controller :

  this.set ('thing'). Then (function () {// success}, this.offlineError ()); // Failure  

Initiator (Note that syntax is for ember-cli):

  Export Default {Name: 'Offline (Container, App) {var = OfflineError = function () {// Some .lookup like containers (' Controller: Application '). ('ShowModal', 'disconnected'); }; App.register ('Offline Error', Offline Error, {Instant: Incorrect}); // Injections AMA (['route', 'controller', 'view']) in routes, controllers and ideas. Each (work (location) {app.inject (location, 'offline error', 'offline error: main');}); }};  

The above code provides an offline error method in all routes, controllers, and ideas, but its beauty is that the method has access to the container without using the private property of Hackney.


Comments

Popular posts from this blog

Member with no value in F# -

java - Joda Time Interval Not returning what I expect -

c# - Showing a SelectedItem's Property -