Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | 34x 34x 224x 14x 14x | import { createAsyncThunk } from '@reduxjs/toolkit';
import { PROJECT_MESSAGES } from '@/shared/constants';
const handleError = (e: unknown): string =>
e instanceof Error ? e.message : PROJECT_MESSAGES.ERROR_ACTION;
export const createThunkWithErrorHandling = <Returned, ThunkArg>(
action: string,
payload: (arg: ThunkArg) => Promise<Returned>,
) =>
createAsyncThunk<Returned, ThunkArg, { rejectValue: string }>(
action,
async (arg, { rejectWithValue }) => {
try {
return await payload(arg);
} catch (e) {
return rejectWithValue(handleError(e));
}
},
);
|