Skip to content

Instantly share code, notes, and snippets.

@hhff
Created September 20, 2019 15:52
Show Gist options
  • Save hhff/9f25f1da1bc811bf9952981c89e403a2 to your computer and use it in GitHub Desktop.
Save hhff/9f25f1da1bc811bf9952981c89e403a2 to your computer and use it in GitHub Desktop.
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