-
Notifications
You must be signed in to change notification settings - Fork 25
/
index.js
54 lines (49 loc) · 1.46 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
const identity = x => x;
const getUndefined = () => {};
const getType = action => action.type;
const filter = () => true;
function createRavenMiddleware(Raven, options = {}) {
// TODO: Validate options.
const {
breadcrumbDataFromAction = getUndefined,
breadcrumbMessageFromAction = getType,
actionTransformer = identity,
stateTransformer = identity,
breadcrumbCategory = "redux-action",
filterBreadcrumbActions = filter,
getUserContext,
getTags
} = options;
return store => {
let lastAction;
Raven.setDataCallback((data, original) => {
const state = store.getState();
const reduxExtra = {
lastAction: actionTransformer(lastAction),
state: stateTransformer(state)
};
data.extra = Object.assign(reduxExtra, data.extra);
if (getUserContext) {
data.user = getUserContext(state);
}
if (getTags) {
data.tags = getTags(state);
}
return original ? original(data) : data;
});
return next => action => {
// Log the action taken to Raven so that we have narrative context in our
// error report.
if (filterBreadcrumbActions(action)) {
Raven.captureBreadcrumb({
category: breadcrumbCategory,
message: breadcrumbMessageFromAction(action),
data: breadcrumbDataFromAction(action)
});
}
lastAction = action;
return next(action);
};
};
}
module.exports = createRavenMiddleware;