How to break a rejected promise using Ember.PromiseProxyMixin

I am using Ember PromiseProxyMixin with AJAX and Ember RSVP Promises data calls. Instead of including error handling in each route / pattern, I would like to issue a rejected promise before the error handler in the application route as follows:

export default Ember.Route.extend({ actions: { error: function(error, transition) { return this.transitionTo('error'); return false; } } }); 

Currently, if a promise is rejected, the rejected promise does not appear in the bubble before the application route (is this because PromiseProxyMixin joins the promise function .fail () and prevents further bubbling? If so, is there a way to continue the bubbles?)

Can I use PromiseProxyMixin and also allow a declined promise to go to the application route?

+7
rsvp-promise
source share
1 answer

I'm not sure it will solve your problem, but we are faced with differences in Es6 promises and jQuery promises, so we will convert all jQuery promises to Es6 by default using the following initializer. We also convert other "thennables" using the when method below:

 import Ember from 'ember'; function initialize() { var $ajax = Ember.$.ajax; Ember.RSVP.when = function(promise, label) { return new Ember.RSVP.Promise(promise.then.bind(promise), label); }; return Ember.$.ajax = function() { return Ember.RSVP.when($ajax.apply(Ember.$, arguments), '$.ajax'); }; }; var PromiseAdapterInitializer = { name: 'promise-adapter', initialize: initialize }; export {initialize}; export default PromiseAdapterInitializer;
import Ember from 'ember'; function initialize() { var $ajax = Ember.$.ajax; Ember.RSVP.when = function(promise, label) { return new Ember.RSVP.Promise(promise.then.bind(promise), label); }; return Ember.$.ajax = function() { return Ember.RSVP.when($ajax.apply(Ember.$, arguments), '$.ajax'); }; }; var PromiseAdapterInitializer = { name: 'promise-adapter', initialize: initialize }; export {initialize}; export default PromiseAdapterInitializer; 
+3
source share

All Articles