error不会返回调用函数的catch块

ix0qys7i  于 2021-09-29  发布在  Java
关注(0)|答案(0)|浏览(144)

被调用函数的catch块不会向调用函数返回promise。

copyFunction = () => {
    this.Service.callCopyFnctn().then((response) => {
      console.log(response);
    }).catch((error) => {
        //This doesn't get invoked 
        console.log(error);
    });
  };

this.copyRetries = 0;
public callCopyFnctn = (): ng.IPromise<any> => {
    var dfd = this.$q.defer();
    let copyHttpRequest: ng.IRequestConfig = {
      'url': //url,
      'method': 'GET',
      'headers': {}
    };

    this.$http(copyHttpRequest).then((response) => {
      dfd.resolve(response.data);
    }).catch((error) => {
// exponentialWaitTime will wait for specific time after making the retry call.
      this.exponentialWaitTime(2 * (this.copyRetries + 1) * 1000).then(() => {
        if (this.copyRetries <= 2 && (error.status === 503 || error.status === 504)) {
          this.copyRetries++;
          this.callCopyFnctn();
        } else {
          dfd.reject(error);
        }
      });
    });
    return dfd.promise;
  };

当我们从 callCopyFnctn 当调用转到else块并 dfd.reject(error) 被调用,但调用不会返回到调用函数catch块,即;不要放弃承诺。
我不明白问题是什么。

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题