2017-09-06 77 views
0

我想知道什麼是從組件中拋出錯誤的最佳方法。在下面的例子中,我檢查是否有一個行爲通過,我拋出一個錯誤,以防止進一步執行這個工作,但是錯誤路由沒有像我期望的那樣被觸發。在餘燼組件中拋出錯誤

/** 
     * Save step and go to the next step. 
     */ 
     next() { 
      if (isEmpty(this.get('nextAction'))) { 
       throw new Error('The nextAction is undefined.'); 
      } 
      if (isEmpty(this.get('saveAction'))) { 
       throw new Error('The saveAction is undefined.'); 
      } 
      const insuranceApplication = this.get('model'); 
      if (this.isLastDependent(this.get('dependentIndex'), insuranceApplication.get('dependents.length'))) { 
       return this.get('nextAction')(); 
      } 
      return this.get('saveAction')().then(() => { 
       this.set('dependent', this.getNextDependent(insuranceApplication.get('dependents'))); 
      }); 
     } 

回答