【问题标题】:Can we handle ngxs @Action errors via ofActionErrored() without going to default "ErrorHandler"?我们可以通过 ofActionErrored() 处理 ngxs @Action 错误而不使用默认的“ErrorHandler”吗?
【发布时间】:2018-11-13 08:58:58
【问题描述】:

我有一个 throwsError() 的异步 ngxs 操作。

我希望默认错误处理机制忽略这个抛出的错误,因为我将通过ofActionErrored() 在我的代码中处理它。但是,对于其他操作,仍应进行默认错误处理。

现在,ofActionErrored() 和默认错误处理(通过 Angular/Ionic)都试图处理错误。

我能想到的替代方法是从最初分派的动作中分派 Xxx_SUCCESS 和 Xxx_ERROR 动作,如果我能提供帮助,我想避免这样做。

建议。

【问题讨论】:

    标签: ngxs


    【解决方案1】:

    在 NGXS 存储库中有一个功能请求引起了类似的关注。我们已经在核心团队会议上进行了讨论,我们将在下一个版本中重点关注这一点。您可以在那里提供您的反馈:https://github.com/ngxs/store/issues/1691

    【讨论】:

      【解决方案2】:

      您可以使用 ofActionCompleted 来提供错误,如果有的话。取自我正在处理的代码的示例:

      this.actions$.pipe(
        ofActionCompleted(GetMe)
      ).subscribe((data) => {
        const errorStatus = data.result.error['status'];
      
        if (!data.result.successful && errorStatus === 403) {
          this.snackbar.openFromComponent(TranslateSnakeBarComponent, {
            data: {message: 'USER_DISABLED'}
          });
        }
      });
      

      【讨论】:

        猜你喜欢
        • 2011-06-29
        • 1970-01-01
        • 2014-10-14
        • 2017-12-22
        • 2019-01-15
        • 1970-01-01
        • 2011-01-12
        • 1970-01-01
        • 2019-11-14
        相关资源
        最近更新 更多