-
Notifications
You must be signed in to change notification settings - Fork 25
/
index.js
79 lines (67 loc) · 2.54 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
'use strict';
Object.defineProperty(exports, '__esModule', {
value: true
});
exports['default'] = createMiddleware;
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
var _ravenJs = require('raven-js');
var _ravenJs2 = _interopRequireDefault(_ravenJs);
var identity = function identity(stuff) {
return stuff;
};
function createMiddleware(dsn) {
var cfg = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1];
var options = arguments.length <= 2 || arguments[2] === undefined ? {} : arguments[2];
/*
Function that generates a crash reporter for Sentry.
dsn - private Sentry DSN.
cfg - object to configure Raven.
options - customize extra data sent to sentry
actionTransformer - tranform the action object to send; default to identity function
stateTransformer - transform the state object to send; default to identity function
logger - the logger to use for logging; default to console.error
*/
if (!_ravenJs2['default'].isSetup()) {
if (!dsn) {
// Skip this middleware if there is no DSN.
console.error('[redux-raven-middleware] Sentry DSN required.');
return function (store) {
return function (next) {
return function (action) {
next(action);
};
};
};
}
_ravenJs2['default'].config(dsn, cfg).install();
}
return function (store) {
return function (next) {
return function (action) {
var _options$actionTransformer = options.actionTransformer;
var actionTransformer = _options$actionTransformer === undefined ? identity : _options$actionTransformer;
var _options$stateTransformer = options.stateTransformer;
var stateTransformer = _options$stateTransformer === undefined ? identity : _options$stateTransformer;
var _options$logger = options.logger;
var logger = _options$logger === undefined ? console.error.bind(console, '[redux-raven-middleware] Reporting error to Sentry:') : _options$logger;
try {
_ravenJs2['default'].captureBreadcrumb({
category: 'redux',
message: action.type
});
return next(action);
} catch (err) {
logger(err);
// Send the report.
_ravenJs2['default'].captureException(err, {
extra: {
action: actionTransformer(action),
state: stateTransformer(store.getState())
}
});
}
};
};
};
}
module.exports = exports['default'];