Created
September 20, 2019 15:52
-
-
Save hhff/9f25f1da1bc811bf9952981c89e403a2 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 * as Sentry from '@sentry/browser'; | |
import { | |
SOME_IGNORED_ACTION, | |
} from 'state/actions/usersActions'; | |
function isPromise(value) { | |
if (value !== null && typeof value === 'object') { | |
return value && typeof value.then === 'function'; | |
} | |
return false; | |
}; | |
const ActionWhitelist = [ | |
SOME_IGNORED_ACTION | |
]; | |
export default store => next => action => { | |
if (!isPromise(action.payload)) return next(action); | |
const promise = next(action); | |
promise.catch(error => { | |
if (ActionWhitelist.includes(action.type)) return error; | |
if (process.env.NODE_ENV === 'development') { | |
console.warn(`Promise Rejected: ${action.type}`, error); | |
} | |
if (process.env.NODE_ENV === 'production') { | |
Sentry.withScope(scope => { | |
scope.setExtra('reduxAction', action.type); | |
scope.setExtra('reduxState', store.getState()); | |
Sentry.captureException(error); | |
}); | |
} | |
return error; | |
}); | |
return promise; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment