mattermost-mobile/app/utils/sentry/middleware.js
Harrison Healey 3ac7b48adc RN-289 Sentry integration (#873)
* Added JS code for Sentry

* Removed leftover initializeSentry call

* Added SentryOptions config setting

* Added native components for react-native-exception-handler

* Removed default props from ErrorText

* Moved where Sentry is initialized

* Added ios/sentry.properties to .gitignore

* Added linking react-native-sentry to Fastlane

* Fixed fastlane to include newlines in sentry.properties

* Moved to manually link react-native-sentry

* Captured redux errors with Sentry

* Redid how Sentry is optionally compiled to be simpler

* Added Sentry middleware to create redux breadcrumbs

* Added Sentry tags for server version

* Initialize Sentry when testing

* Fixed string replacement for SentryEnabled in fastlane

* Added react-native-sentry to NOTICE.txt
2017-09-01 14:50:17 -03:00

43 lines
1.2 KiB
JavaScript

// Copyright (c) 2017-present Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.
import {Sentry} from 'react-native-sentry';
import {BATCH} from 'redux-batched-actions';
export const BREADCRUMB_REDUX_ACTION = 'redux-action';
export function createSentryMiddleware() {
return (store) => { // eslint-disable-line no-unused-vars
return (next) => {
return (action) => {
Sentry.captureBreadcrumb(makeBreadcrumbFromAction(action));
return next(action);
};
};
};
}
function makeBreadcrumbFromAction(action) {
const breadcrumb = {
category: BREADCRUMB_REDUX_ACTION,
message: action.type
};
if (action.type === BATCH) {
// Attach additional information so that batched actions display what they're doing
breadcrumb.data = action.payload.map((a) => a.type);
}
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;
});
}
return breadcrumb;
}