gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 00:06:22 25 4
gpt4 key购买 nike

我有一个效果,它的主要思想是用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 use ineffects and Epiks is禁止。我做错了什么?为什么它过去可以与这样的代码一起工作(通过 linting)?

@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 })))
);

最佳答案

您必须对每个服务方法使用catchError,例如

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

关于javascript - RxJS:禁止在效果和史诗中使用不安全的捕获并请求嵌套,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60352765/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com