Last active
February 19, 2023 14:45
-
-
Save safronman/1cf66c1c4128b33398f7ca707322d565 to your computer and use it in GitHub Desktop.
thunkTryCatch
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| export const changeCourseId = createAsyncThunk( | |
| 'auth/change-course', | |
| async (payload: PayloadType, thunkAPI) => { | |
| return thunkTryCatch(thunkAPI, async () => { | |
| await packsApi.put(payload) | |
| }) | |
| } | |
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { hostAppActions } from '../../app/host-app-slice' | |
| export const thunkTryCatch = async (thunkAPI: any, logic: Function) => { | |
| try { | |
| return await logic() | |
| } catch (e: any) { | |
| const error = e.response ? e.response.data.error : e.message + ', more details in the console' | |
| // thunkAPI.dispatch(appThunks.setAppError({ error })) | |
| thunkAPI.dispatch(hostAppActions.showSnackbar({ message: error, severity: 'error' })) | |
| return thunkAPI.rejectWithValue({ error }) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment