【问题标题】:How can I get the error from nestjs to angular with pipe()?如何使用 pipe() 从nestjs 获取错误到角度?
【发布时间】:2019-12-16 21:18:55
【问题描述】:

显示代码

 this.authService
  .login(payload)
  .pipe(
    map((e: any) => e.token),
    tap(e => dispatch(new AuthLoginSuccess(e)))
  )
  .subscribe();

我试图显示从nestjs 后端返回到我的角度前端的错误。如果发布了正确的凭据,上述函数将返回令牌。我无法获取错误

【问题讨论】:

  • 请澄清问题,目前尚不清楚您要完成什么。
  • 请为您的问题添加更多描述并显示更多代码。 distpatch(new AuthLoginSuccess(e)) 是做什么的?有哪些类型? this.authService.login(payload) 返回什么?模拟有效载荷是什么样的?
  • 我正在尝试获取从 nestjs 后端到角度前端的任何错误
  • distpatch(new AuthLoginSuccess(e)) 用于登录成功后做一些功能

标签: angular redux nestjs ngxs


【解决方案1】:

使用 RxJS 来捕获任何需要使用 catchError() 运算符的错误,类似于使用 tapmap 的方式。另一种选择是为subscribe() 方法提供一个错误观察器​​并在那里处理它。根据您要对错误执行的操作,两者都可能有用。

【讨论】:

    【解决方案2】:
      .login(payload)
      .pipe(
        map((e: any) => e.token),
        tap(e => dispatch(new AuthLoginSuccess(e))),
        catchError(error => { .... do stuff .... } )
      )
      .subscribe();
    

    这应该允许您从服务中获取任何错误。

    【讨论】:

      猜你喜欢
      • 2021-08-29
      • 1970-01-01
      • 1970-01-01
      • 2016-11-04
      • 1970-01-01
      • 2019-06-30
      • 2016-01-20
      • 1970-01-01
      • 2018-10-25
      相关资源
      最近更新 更多