Created
September 20, 2017 20:29
-
-
Save akhayoon/24be6ca9634d228893b8c4bd79f0f33c to your computer and use it in GitHub Desktop.
This file contains 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 Raven from 'raven-js' | |
// Custom Redux-Thunk that catches errors | |
function createThunkMiddleware(extraArgument) { | |
return ({ dispatch, getState }) => next => action => | |
{ | |
if (typeof action === 'function') | |
{ | |
const result = action(dispatch, getState, extraArgument); | |
// If the function returns a promise (async function usually), then | |
// catch the error manually and report to Raven. | |
if (result && result.catch && typeof(result.catch) === 'function') | |
{ | |
return result.catch((error) => | |
{ | |
console.error(error); | |
Raven.captureException(error); | |
}); | |
} | |
return result; | |
} | |
return next(action); | |
} | |
} | |
const enhancedReduxThunk = createThunkMiddleware(); | |
enhancedReduxThunk.withExtraArgument = createThunkMiddleware; | |
export default enhancedReduxThunk; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment