Angular2 rxjs - switchmap catch error

前端 未结 1 1508
无人共我
无人共我 2021-02-13 00:47

I\'d like to be able to handle any errors that error when calling this.authService.refreshToken(). Can errors be handled within the switchmap block, or how do I go

相关标签:
1条回答
  • 2021-02-13 01:08

    use the catchError method

    this.authService.refreshToken()
      .pipe(
         switchMap(() => {...}),
         catchError((e) => {
           // handle e and return a safe value or re-throw
           if (isCritical(e)) {
             return throwError(e);
           }
           return of([]);
        })
      );
    
    0 讨论(0)
提交回复
热议问题