Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Customized error serialization for createAsyncTask #644

Closed
Yserz opened this issue Jul 1, 2020 · 1 comment
Closed

Customized error serialization for createAsyncTask #644

Yserz opened this issue Jul 1, 2020 · 1 comment
Milestone

Comments

@Yserz
Copy link

Yserz commented Jul 1, 2020

Hey,

I'm having a hard time with error mapping using reduxjs/redux-toolkit. The situation is as follows:

  1. When any backend request fails it results in an error of the form:
    { message: string, code: number, label: string, }
  2. When the thunk rejects the error gets serialized by miniSerializeError
    export const miniSerializeError = (value: any): SerializedError => {

Result:
The label is stripped from the error.

Expected result:
createAsyncTask can be (globally) configured to keep certain attributes on errors from rejections. This could be fully optional and default to the current values.

Note when using thunkAPI.rejectWithValue:

  1. The API feels to be inconsistent because the error in the action is in the payload instead of in the error attribute. There is an error in the error field though but is only including the message attribute of the error.
  2. When using unwrapResult on such a value it will throw only the error from the error attribute which makes further code necessary to get the actual error from the rejected action.

IMHO it would be best to allow to specify which additional attributes on an error should be serialized when a thunk gets rejected in order to use the API in the usual way.

Related issues:
#588

@markerikson
Copy link
Collaborator

Fixed by #812 , I believe.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants