Solved (partly) : Promise: How to turn off reject / fulfilled or handle them?


#1

I have component which I’m testing when it cannot get ManyTo model for visitor (404). This brakes our application if for 1 milisecond our server will be down. Not ideal scenario.

How to reset the state of promise ?

click(question) {
  question.get('breedCodes').then(() => {
    console.log('component show list');
  }).catch(function (err) {
    console.log('no list, try again in 1 second');
  }
}

I’ve checked all of the topics in this forum, checked in 10 h all the internet including guidelines from ember, ember API, ember-data API, git source, RSVP, Promises etc. I want to cry how complicated that is. I didn’t ask for caching my question to ember-data. :frowning:

UPDATE

Looks like proxy works however adapter is aborting as it looks that the statment of adapter is saved :frowning_face:

      let ObjectPromiseProxy = ObjectProxy.extend(PromiseProxyMixin);
      let proxy = ObjectPromiseProxy.create({
        promise: question.get('breedCodes')
      });
      proxy.then(function(json){
        console.log('run correct');
      }, function(reason) {
        if(proxy.get('isRejected')) {
          proxy.set('promise',question.get('breedCodes') );
          console.log('You are not allowed to post here.');
        }

      });

UPDATE 2

I refactor code by adding tryAgain on which I’m reloading model and returning promise (question.get(‘breedCodes’).reload()).