Skip to content

Instantly share code, notes, and snippets.

@ger86
Created November 27, 2018 18:00
Show Gist options
  • Save ger86/b321f5b644da0e4cfc1726a6d1f8f9a4 to your computer and use it in GitHub Desktop.
Save ger86/b321f5b644da0e4cfc1726a6d1f8f9a4 to your computer and use it in GitHub Desktop.
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