Skip to content
This repository was archived by the owner on Sep 3, 2022. It is now read-only.

Catch and guard against Integration errors #66

Merged
merged 1 commit into from
Apr 19, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion lib/analytics.js
Original file line number Diff line number Diff line change
Expand Up @@ -615,7 +615,11 @@ Analytics.prototype._invoke = function(method, facade) {
if (failedInitializations.indexOf(name) >= 0) {
self.log('Skipping invokation of .%s method of %s integration. Integation failed to initialize properly.', method, name);
} else {
integration.invoke.call(integration, method, facade);
try {
integration.invoke.call(integration, method, facade);
} catch (e) {
self.log('Error invoking .%s method of %s integration: %o', method, name, e);
}
}
}, this._integrations);

Expand Down
5 changes: 5 additions & 0 deletions test/analytics.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,11 @@ describe('Analytics', function() {
assert(!Test.prototype.invoke.called);
});

it('should not crash when invoking integration fails', function() {
Test.prototype.invoke = function() { throw new Error('Uh oh!'); };
analytics.track('Test Event');
});

it('should support .integrations to disable / select integrations', function() {
var opts = { integrations: { Test: false } };
analytics.identify('123', {}, opts);
Expand Down