mattermost-mobile/app/store/middlewares/sentry.js
Elias Nahum 8e314022ca
MM-24285 Use FastImage instead of Image (#4218)
* Enable ESLint no-unused-vars

* Use FastImage instead of Image

* Update fast-image patch to support multiple cookies

* Fix ESLint errors

* Have jest run timers for post_textbox tests

* Feedback review

* Update snapshots
2020-04-28 11:36:32 -04:00

42 lines
1.2 KiB
JavaScript

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import {BATCH} from 'redux-batched-actions';
export const BREADCRUMB_REDUX_ACTION = 'redux-action';
let Sentry;
export default function createSentryMiddleware() {
if (!Sentry) {
Sentry = require('@sentry/react-native');
}
return () => (next) => (action) => {
Sentry.addBreadcrumb(makeBreadcrumbFromAction(action));
return next(action);
};
}
function makeBreadcrumbFromAction(action) {
if (!action.type) {
console.warn('dispatching action with undefined type', action); // eslint-disable-line no-console
}
const breadcrumb = {
category: BREADCRUMB_REDUX_ACTION,
message: action.type || 'undefined action',
};
if (action.type === BATCH) {
// Attach additional information so that batched actions display what they're doing, and make it
// into an object because that's what is expected
breadcrumb.data = {};
action.payload.forEach((a, index) => {
breadcrumb.data[index] = a.type || 'undefined action';
});
}
return breadcrumb;
}