代码之家  ›  专栏  ›  技术社区  ›  Ricardo Rocha

将映射函数从rxjs5迁移到rxjs6

  •  1
  • Ricardo Rocha  · 技术社区  · 6 年前

    return this.http.put(url, image, options).map((res, err) => {
          return res;
        }).catch(err => {
          if (err.error instanceof Error) {
            return err.error;
          } else {
            throw Observable.throw(err);
          }
        });
    

    我想到了这个解决方案:

    return this.http.put(url, image, options).pipe(map((res, err) => {
          return res;
        }));
    

    但问题是我不知道我是否没有迁移 .catch

    您能建议迁移以下代码的最佳方法吗?

    1 回复  |  直到 6 年前
        1
  •  2
  •   Lazar Ljubenović    6 年前

    catch catchError . 和我一样 throw throwError .

    return this.http.put(url, image, options).pipe(
      map((res, err) => {
        return res;
      }),
      catchError(error => throwError(error))
    );