【问题标题】:error handling inside ngrx effectsngrx 效果中的错误处理
【发布时间】:2019-01-17 13:27:01
【问题描述】:

我知道整个网络都有关于效果错误处理的示例,但在我的情况下,我没有调用一个 http 服务,它返回一个可观察的,就像我发现的 99% 的示例一样,所以我对构建这些示例感到茫然操作符来获得想要的效果。

我需要将我的 catchError() 移到我的 switchMap() 中

switchMap( ( [ routerState, state ] ) => {

    const tenantKey = routerState.params[ 'tenantKey' ];
    if ( state ) {
      if ( state.tenant && state.tenant.id === tenantKey ) {
        return of( { type: '[TenantContext] Tenant Context Check Valid', payload: state.tenant } );
      } else {
        return of( new LoadContextAction( tenantKey ) );
      }

    } else {
      return of( new LoadContextAction( tenantKey ) );
    }

  } ),
  catchError( ( err ) => {
    return of( { type: '[TenantContext] Error', payload: err } );
  } )

【问题讨论】:

    标签: ngrx-effects rxjs6


    【解决方案1】:

    我最终用地图替换了 switchMap。

    map( ( [ routerState, state ] ) => {
      const tenantKey = routerState.params[ 'tenantKey' ];
      if ( state ) {
        if ( state && state.id === tenantKey ) {
          return {
            type: '[TenantClubContext] Tenant Context Check Valid',
            payload: state
          };
        } else {
          return new LoadContextAction( tenantKey );
        }
      } else {
        return new LoadContextAction( tenantKey );
      }
    } ),
    catchError( err => {
      return of( { type: '[TenantClubContext] Error', payload: err } );
    } )
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-10-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-05-26
      相关资源
      最近更新 更多