RxJS:禁止在效果和史诗中使用不安全的捕获,并要求嵌套

问题描述 投票:0回答:1

我有一个效果,主要思想是用API做出一些“魔术”,这是主要问题:首先,我需要发出一个请求,成功后,我需要发出第二个请求。一切正常,直到我将代码更改为此(看起来更具可读性):

@Effect()
    myEffect$ = this.actions$.pipe(
        ofType(actionTypes.SomeDataAction),
        withLatestFrom(this.store.select(selectTheAwesome)),
        concatMap(([action, awesomeData]) =>
            forkJoin([
                of(awesomeData),
                this.myService.makeFirstMagic(
                    action.payload.someDataId
                )
            ])
        ),
        concatMap(data => {
            const [awesomeData, magicFirst] = data;

            return this.myService.makeSecondMagic(awesomeData.awesomeDataId, magicFirst.newId).pipe(
                mergeMap(response => {
                    return [new SomeDataActionSuccess(), new SomeAnotherDataAction([response])];
                })
            );
        }),
        catchError((error) => of(new SomeDataActionError({ error })))
    );

但结果ts-lint失败,并显示RxJS: Unsafe catch usage in effects and epics is forbidden。我做错了什么?为什么以前用这样的代码工作(通过掉毛)?

@Effect()
    myEffect$ = this.actions$.pipe(
        ofType(actionTypes.SomeDataAction),
        withLatestFrom(this.store.select(selectTheAwesome)),
        mergeMap(([action, awesomeData]) => {
            return this.myService.makeFirstMagic(action.payload.someDataId).pipe(
                mergeMap(magicFirst => {
                    return this.myService.makeSecondMagic(awesomeData.awesomeDataId, magicFirst.newId).pipe(
                        mergeMap(response => {
                            return [new SomeDataActionSuccess(), new SomeAnotherDataAction([response])];
                        })
                    );
                })
            );
        }),
        catchError(error => of(new SomeDataActionError({ error })))
    );

javascript typescript rxjs ngrx tslint
1个回答
0
投票

例如,每种服务方法都必须使用catchError

this.myService.makeSecondMagic(awesomeData.awesomeDataId, magicFirst.newId).pipe(
                mergeMap(response => {
                    return [new SomeDataActionSuccess(), new SomeAnotherDataAction([response])];
                }),
                catchError(....)
            );

© www.soinside.com 2019 - 2024. All rights reserved.