Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import { Middleware, Store, Dispatch } from 'redux';
- import Raven from 'raven-js';
- const loggerKey = '[redux-raven-middleware]';
- export default (dsn, config = {}) => {
- if (!Raven.isSetup()) {
- if (!dsn) {
- // skip this middleware if there is no DSN (Data Source Name).
- console.error(`${loggerKey} Sentry DSN required.`);
- return store => next => action => next(action);
- }
- Raven.config(dsn, config).install();
- }
- return ({ getState }: Store) => (next: Dispatch) => (action: any): any => {
- const state: IAppState = getState();
- try {
- return next(action);
- } catch (err) {
- try {
- const { authentication, settings: { endpoint } } = state;
- if (authentication.isAuthenticated && authentication.user) {
- Raven.setUserContext({ email: authentication.user.email });
- } else {
- Raven.setUserContext();
- }
- (Raven as any).setExtraContext({ disco_api_endpoint: endpoint });
- } catch (fatalErr) {
- console.error(`Unexpected fatal error in Raven middleware: ${fatalErr}`);
- }
- console.error(`${loggerKey} Reporting error to Sentry:`, err);
- // Send the report.
- Raven.captureException(err, { extra: { action, state } });
- }
- }
- }
- /** WEBPACK FOOTER **
- ** ./~/tslint-loader!./src/app/store/middleware/raven.ts
- **/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement