Skip to content
This repository was archived by the owner on Nov 23, 2019. It is now read-only.

Commit f48eb1f

Browse files
committed
fix: check if callback is null before invoking
1 parent cc762bf commit f48eb1f

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

lib/index.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -440,9 +440,12 @@ Segment.prototype.retrieveCrossDomainId = function(callback) {
440440

441441
var cachedCrossDomainId = this.getCachedCrossDomainId();
442442
if (cachedCrossDomainId) {
443-
callback(null, {
444-
crossDomainId: cachedCrossDomainId
445-
});
443+
// Callback is only provided in tests.
444+
if (callback) {
445+
callback(null, {
446+
crossDomainId: cachedCrossDomainId
447+
});
448+
}
446449
return;
447450
}
448451

@@ -461,11 +464,12 @@ Segment.prototype.retrieveCrossDomainId = function(callback) {
461464

462465
getCrossDomainIdFromServerList(domains, writeKey, function(err, res) {
463466
if (err) {
464-
// We optimize for no conflicting xid as much as possible. So bail out if there is an
465-
// error and we cannot be sure that xid does not exist on any other domains
467+
// Callback is only provided in tests.
466468
if (callback) {
467469
callback(err, null);
468470
}
471+
// We optimize for no conflicting xid as much as possible. So bail out if there is an
472+
// error and we cannot be sure that xid does not exist on any other domains.
469473
return;
470474
}
471475

0 commit comments

Comments
 (0)