I'm using Redux Toolkit and I have several slices:
user: {
profile: {}
daysOff: {}
}
offers: {
fetchedOffers: {}
publishedOffer: {}
}
general: {}
Each of them has its own Async Thunks and as a result, each of them has its own error: "value" pair.
I'd like to somehow create a global Error slice, which will have errorMsg key where I could store error messages from other slices.
The idea is to handle all errors on UI from a single place. I will check Error global slice only, if it has some error message, I would display it to the user. When user clicks on a pop up or alert with the message, I will clear the errorMsg so it wouldn't display anymore until another thunk is dispatched.
I'm not sure whether this is an adequate logic but I believe it's ok, however, I have no idea how to create this global slice which will be able to get error from other slices.
The resulting state tree would look like this:
user: {
profile: {}
daysOff: {}
}
offers: {
fetchedOffers: {}
publishedOffer: {}
}
general: {}
error: {
message: 'email or password is invalid' or 'incorrect filter parameters'...whatever the
message is
}
Can anybody suggest how can I do something like this, please?