Skip to content

Commit 34b845a

Browse files
author
Thomas Grainger
committed
ensure angular and react-native wrap callbacks without altering Raven API
1 parent 2591620 commit 34b845a

File tree

4 files changed

+24
-30
lines changed

4 files changed

+24
-30
lines changed

plugins/angular.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
*/
66
'use strict';
77

8+
var wrappedCallback = require('../utils/wrappedCallback').wrappedCallback;
9+
810
// See https://github.com/angular/angular.js/blob/v1.4.7/src/minErr.js
911
var angularPattern = /^\[((?:[$a-zA-Z0-9]+:)?(?:[$a-zA-Z0-9]+))\] (.*?)\n?(\S+)$/;
1012

@@ -38,9 +40,9 @@ function angularPlugin(Raven, angular) {
3840
.provider('Raven', RavenProvider)
3941
.config(['$provide', ExceptionHandlerProvider]);
4042

41-
Raven.wrapDataCallback(function(data) {
43+
Raven.setDataCallback(wrappedCallback(function(data) {
4244
return angularPlugin._normalizeData(data);
43-
});
45+
}));
4446
}
4547

4648
angularPlugin._normalizeData = function (data) {

plugins/react-native.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919
*/
2020
'use strict';
2121

22+
23+
var wrappedCallback = require('../utils/wrappedCallback').wrappedCallback;
24+
2225
// Example React Native path format (iOS):
2326
// /var/containers/Bundle/Application/{DEVICE_ID}/HelloWorld.app/main.jsbundle
2427

@@ -60,9 +63,9 @@ function reactNativePlugin(Raven, options) {
6063
Raven.setTransport(reactNativePlugin._transport);
6164

6265
// Use data callback to strip device-specific paths from stack traces
63-
Raven.wrapDataCallback(function(data) {
66+
Raven.setDataCallback(wrappedCallback(function(data) {
6467
return reactNativePlugin._normalizeData(data, options.pathStrip);
65-
});
68+
}));
6669

6770
// Check for a previously persisted payload, and report it.
6871
reactNativePlugin._restorePayload()

src/raven.js

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -33,18 +33,6 @@ function keepOriginalCallback(original, callback) {
3333
callback;
3434
}
3535

36-
function wrappedCallback(callback) {
37-
function dataCallback(data, original) {
38-
var normalizedData = callback(data) || data;
39-
if (original) {
40-
return original(normalizedData) || normalizedData;
41-
}
42-
return normalizedData;
43-
}
44-
45-
return dataCallback;
46-
}
47-
4836
// First, check for JSON support
4937
// If there is no JSON, we no-op the core features of Raven
5038
// since JSON is required to encode the payload
@@ -574,10 +562,6 @@ Raven.prototype = {
574562
return this;
575563
},
576564

577-
wrapDataCallback: function(callback) {
578-
return this.setDataCallback(wrappedCallback(callback));
579-
},
580-
581565
/*
582566
* Set the breadcrumbCallback option
583567
*
@@ -592,10 +576,6 @@ Raven.prototype = {
592576
return this;
593577
},
594578

595-
wrapBreadcrumbCallback: function(callback) {
596-
return this.setBreadcrumbCallback(wrappedCallback(callback));
597-
},
598-
599579
/*
600580
* Set the shouldSendCallback option
601581
*
@@ -610,10 +590,6 @@ Raven.prototype = {
610590
return this;
611591
},
612592

613-
wrapShouldSendCallback: function(callback) {
614-
return this.setShouldSendCallback(wrappedCallback(callback));
615-
},
616-
617593
/**
618594
* Override the default HTTP transport mechanism that transmits data
619595
* to the Sentry server.

src/utils.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,20 @@ function isError(what) {
1414
what instanceof Error;
1515
}
1616

17+
function wrappedCallback(callback) {
18+
function dataCallback(data, original) {
19+
var normalizedData = callback(data) || data;
20+
if (original) {
21+
return original(normalizedData) || normalizedData;
22+
}
23+
return normalizedData;
24+
}
25+
26+
return dataCallback;
27+
}
28+
1729
module.exports = {
1830
isObject: isObject,
19-
isError: isError
20-
};
31+
isError: isError,
32+
wrappedCallback: wrappedCallback
33+
};

0 commit comments

Comments
 (0)