有没有办法使'端点。
我派遣a rtkquery突变
const result = await dispatch(
commentsApi.endpoints.myEndpoint.initiate(params)
)
注意到,当基础请求失败时,这不会抛出异常 - 上面的dispatch
呼叫syolves
将其带入具有error
属性的对象。
这是什么原因?我更喜欢拒绝
,所以我可以这样使用它:
try {
await dispatch(commentsApi.endpoints.myEndpoint.initiate(params))
someOtherCallDependentOnMutationSuccess()
} catch (e) {
// ...
}
有没有办法使所有endpoint.initiate()
调用呼叫拒绝在基础请求失败时拒绝?还是有充分的理由不想要?
I dispatch a RTKQuery mutation inside a custom thunk like this:
const result = await dispatch(
commentsApi.endpoints.myEndpoint.initiate(params)
)
and I noticed that when the underlying request fails, this does not throw an exception - the above dispatch
call resolves
into an object with an error
property instead.
What is the reason for that? I would prefer rejecting
, so I could use it like this:
try {
await dispatch(commentsApi.endpoints.myEndpoint.initiate(params))
someOtherCallDependentOnMutationSuccess()
} catch (e) {
// ...
}
Is there a way to make all endpoint.initiate()
calls reject when the underlying request fails? Or is there a good reason not to want that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以更改逻辑,以使
dispatch
使用.unwrap()
:You can change the logic to make the
dispatch
throw an error using.unwrap()
: