I can't get a rejected promise in my try catch block, it's response is always in the originalPromiseResult
Here is the slice where I get some data from the API:
export const getData = createAsyncThunk(
'user/getData',
async (headers, { rejectWithValue }) => {
try {
return await httpService.getData(headers)
} catch (err) {
console.error(e)
return rejectWithValue(err.response.data)
}
}
)
And here is my component:
const dispatch = useDispatch()
const myCallback = async (data) => {
try {
const originalPromiseResult = await dispatch(getData(data))
} catch (error) {
console.log('error = ', error)
}
}