Created
November 27, 2018 18:00
-
-
Save ger86/b321f5b644da0e4cfc1726a6d1f8f9a4 to your computer and use it in GitHub Desktop.
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 createRequest = ( | |
| { requestId, requestParams } | |
| ) => async (dispatch, getState) => { | |
| const cancelTokenSource = request.getCancelTokenSource(); | |
| dispatch(requestStartedAction(requestId, cancelTokenSource)); | |
| try { | |
| const res = await request.send({ | |
| ...requestParams, | |
| cancelToken: cancelTokenSource.token | |
| }); | |
| dispatch(requestSucceededAction(requestId)); | |
| return res; | |
| } catch (error) { | |
| if (error.message === 'cancelled') { | |
| throw error; | |
| } | |
| dispatch(requestFailedAction(requestId, error)); | |
| throw error; | |
| } | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment