redux-toolkit: Can UnwrapResult prefer payload error?
In unwrapResult, we throw returned.error, which for custom handlers is always “Rejected” Can we throw payload.error if it exists before throwing returned.error? (Is there a way to overwrite returned.error that I didn’t see in rejectWithValue?)
export function unwrapResult<R extends ActionTypesWithOptionalErrorAction>(
returned: R
): PayloadForActionTypesExcludingErrorActions<R> {
if ('error' in returned) {
throw returned.error
}
return (returned as any).payload
}
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 23 (9 by maintainers)
Commits related to this issue
- fix unwrapResult behaviour this fixes #701 — committed to phryneas/redux-toolkit by deleted user 4 years ago
- fix unwrapResult behaviour this fixes #701 — committed to phryneas/redux-toolkit by deleted user 4 years ago
- fix unwrapResult behaviour this fixes #701 — committed to phryneas/redux-toolkit by deleted user 4 years ago
- fix unwrapResult behaviour (#704) * fix unwrapResult behaviour this fixes #701 * fix inconsistent type, add api report * udpate docs * remove another useless `unwrapResult` — committed to reduxjs/redux-toolkit by deleted user 4 years ago
- Fixed undefined error alert message. There was a timing issue with the error state being updated after the dispatch. Instead of using a selector inside of the dispatch promise, I used rejectedValueOrS... — committed to JFBarryLi/fea-ui by JFBarryLi 4 years ago
I’d opt for adding
action.meta.rejectedWithValue
(like we already haveaction.meta.aborted
andaction.meta.condition
) and doing something likePS: on the other hand, that
undefined
handling will mock up the return value, so maybe just let JS error out on that