如何使用 pipe() 从 nestjs 获取错误到 angular?
How can I get the error from nestjs to angular with pipe()?
显示代码
this.authService
.login(payload)
.pipe(
map((e: any) => e.token),
tap(e => dispatch(new AuthLoginSuccess(e)))
)
.subscribe();
我正在尝试显示从 nestjs 后端返回到我的 angular 前端的错误。如果发布了正确的凭据,则上述函数 returns 令牌。我无法获得错误
使用 RxJS 捕获任何错误,您需要使用 catchError()
运算符,类似于您使用 tap
和 map
的方式。另一种选择是为 subscribe()
方法提供一个错误观察器并在那里处理它。根据您要对错误执行的操作,两者都有用。
.login(payload)
.pipe(
map((e: any) => e.token),
tap(e => dispatch(new AuthLoginSuccess(e))),
catchError(error => { .... do stuff .... } )
)
.subscribe();
这应该允许您从服务中获取任何错误。
显示代码
this.authService
.login(payload)
.pipe(
map((e: any) => e.token),
tap(e => dispatch(new AuthLoginSuccess(e)))
)
.subscribe();
我正在尝试显示从 nestjs 后端返回到我的 angular 前端的错误。如果发布了正确的凭据,则上述函数 returns 令牌。我无法获得错误
使用 RxJS 捕获任何错误,您需要使用 catchError()
运算符,类似于您使用 tap
和 map
的方式。另一种选择是为 subscribe()
方法提供一个错误观察器并在那里处理它。根据您要对错误执行的操作,两者都有用。
.login(payload)
.pipe(
map((e: any) => e.token),
tap(e => dispatch(new AuthLoginSuccess(e))),
catchError(error => { .... do stuff .... } )
)
.subscribe();
这应该允许您从服务中获取任何错误。