Skip to content
Draft
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
4 changes: 3 additions & 1 deletion src/apiClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { IMParticleUser, ISDKUserAttributes } from './identity-user-interfaces';
import { AsyncUploader, FetchUploader, XHRUploader } from './uploaders';
import { IMParticleWebSDKInstance } from './mp-instance';
import { appendUserInfo } from './user-utils';
import { ErrorCodes } from './logging/errorCodes';

export interface IAPIClient {
uploader: BatchUploader | null;
Expand Down Expand Up @@ -172,7 +173,8 @@ export default function APIClient(
}
} catch (e) {
mpInstance.Logger.error(
'Error sending forwarding stats to mParticle servers.'
'Error sending forwarding stats to mParticle servers.',
ErrorCodes.API_CLIENT_ERROR
);
}
};
Expand Down
4 changes: 3 additions & 1 deletion src/audienceManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
IFetchPayload
} from './uploaders';
import Audience from './audience';
import { ErrorCodes } from './logging/errorCodes';

export interface IAudienceMembershipsServerResponse {
dt: 'cam'; // current audience memberships
Expand Down Expand Up @@ -81,7 +82,8 @@ export default class AudienceManager {
}
} catch (e) {
this.logger.error(
`Error retrieving audiences. ${e}`
`Error retrieving audiences. ${e}`,
ErrorCodes.AUDIENCE_MANAGER_ERROR
);
}
}
Expand Down
10 changes: 7 additions & 3 deletions src/batchUploader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { IMParticleUser } from './identity-user-interfaces';
import { IMParticleWebSDKInstance } from './mp-instance';
import { appendUserInfo } from './user-utils';
import { IntegrationAttributes } from './store';
import { ErrorCodes } from './logging/errorCodes';
/**
* BatchUploader contains all the logic to store/retrieve events and batches
* to/from persistence, and upload batches to mParticle.
Expand Down Expand Up @@ -489,13 +490,15 @@ export class BatchUploader {
response.status === 429
) {
logger.error(
`HTTP error status ${response.status} received`
`HTTP error status ${response.status} received`,
ErrorCodes.BATCH_UPLOADER_ERROR
);
// Server error, add back current batches and try again later
return uploads.slice(i, uploads.length);
} else if (response.status >= 401) {
logger.error(
`HTTP error status ${response.status} while uploading - please verify your API key.`
`HTTP error status ${response.status} while uploading - please verify your API key.`,
ErrorCodes.BATCH_UPLOADER_ERROR
);
//if we're getting a 401, assume we'll keep getting a 401 and clear the uploads.
return null;
Expand All @@ -512,7 +515,8 @@ export class BatchUploader {
}
} catch (e) {
logger.error(
`Error sending event to mParticle servers. ${e}`
`Error sending event to mParticle servers. ${e}`,
ErrorCodes.BATCH_UPLOADER_ERROR
);
return uploads.slice(i, uploads.length);
}
Expand Down
24 changes: 16 additions & 8 deletions src/consent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import KitFilterHelper from './kitFilterHelper';
import Constants from './constants';
import { IMParticleUser } from './identity-user-interfaces';
import { IMParticleWebSDKInstance } from './mp-instance';
import { ErrorCodes } from './logging/errorCodes';

const { CCPAPurpose } = Constants;

Expand Down Expand Up @@ -183,31 +184,36 @@ export default function Consent(this: IConsent, mpInstance: IMParticleWebSDKInst
): PrivacyConsentState | null {
if (typeof consented !== 'boolean') {
mpInstance.Logger.error(
'Consented boolean is required when constructing a Consent object.'
'Consented boolean is required when constructing a Consent object.',
ErrorCodes.CONSENT_ERROR
);
return null;
}
if (timestamp && isNaN(timestamp)) {
mpInstance.Logger.error(
'Timestamp must be a valid number when constructing a Consent object.'
'Timestamp must be a valid number when constructing a Consent object.',
ErrorCodes.CONSENT_ERROR
);
return null;
}
if (consentDocument && typeof consentDocument !== 'string') {
mpInstance.Logger.error(
'Document must be a valid string when constructing a Consent object.'
'Document must be a valid string when constructing a Consent object.',
ErrorCodes.CONSENT_ERROR
);
return null;
}
if (location && typeof location !== 'string') {
mpInstance.Logger.error(
'Location must be a valid string when constructing a Consent object.'
'Location must be a valid string when constructing a Consent object.',
ErrorCodes.CONSENT_ERROR
);
return null;
}
if (hardwareId && typeof hardwareId !== 'string') {
mpInstance.Logger.error(
'Hardware ID must be a valid string when constructing a Consent object.'
'Hardware ID must be a valid string when constructing a Consent object.',
ErrorCodes.CONSENT_ERROR
);
return null;
}
Expand Down Expand Up @@ -381,13 +387,14 @@ export default function Consent(this: IConsent, mpInstance: IMParticleWebSDKInst
): ConsentState {
const normalizedPurpose = canonicalizeForDeduplication(purpose);
if (!normalizedPurpose) {
mpInstance.Logger.error('Purpose must be a string.');
mpInstance.Logger.error('Purpose must be a string.', ErrorCodes.CONSENT_ERROR);
return this;
}

if (!isObject(gdprConsent)) {
mpInstance.Logger.error(
'Invoked with a bad or empty consent object.'
'Invoked with a bad or empty consent object.',
ErrorCodes.CONSENT_ERROR
);
return this;
}
Expand Down Expand Up @@ -466,7 +473,8 @@ export default function Consent(this: IConsent, mpInstance: IMParticleWebSDKInst
) {
if (!isObject(ccpaConsent)) {
mpInstance.Logger.error(
'Invoked with a bad or empty CCPA consent object.'
'Invoked with a bad or empty CCPA consent object.',
ErrorCodes.CONSENT_ERROR
);
return this;
}
Expand Down
35 changes: 25 additions & 10 deletions src/ecommerce.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Types from './types';
import Constants from './constants';
import { ErrorCodes } from './logging/errorCodes';

var Messages = Constants.Messages;

Expand Down Expand Up @@ -116,7 +117,8 @@ export default function Ecommerce(mpInstance) {
mpInstance.Logger.error(
'Could not convert product action type ' +
productActionType +
' to event type'
' to event type',
ErrorCodes.ECOMMERCE_ERROR
);
return null;
}
Expand All @@ -132,7 +134,8 @@ export default function Ecommerce(mpInstance) {
mpInstance.Logger.error(
'Could not convert promotion action type ' +
promotionActionType +
' to event type'
' to event type',
ErrorCodes.ECOMMERCE_ERROR
);
return null;
}
Expand Down Expand Up @@ -262,20 +265,25 @@ export default function Ecommerce(mpInstance) {
attributes = mpInstance._Helpers.sanitizeAttributes(attributes, name);

if (typeof name !== 'string') {
mpInstance.Logger.error('Name is required when creating a product');
mpInstance.Logger.error(
'Name is required when creating a product',
ErrorCodes.ECOMMERCE_ERROR
);
return null;
}

if (!mpInstance._Helpers.Validators.isStringOrNumber(sku)) {
mpInstance.Logger.error(
'SKU is required when creating a product, and must be a string or a number'
'SKU is required when creating a product, and must be a string or a number',
ErrorCodes.ECOMMERCE_ERROR
);
return null;
}

if (!mpInstance._Helpers.Validators.isStringOrNumber(price)) {
mpInstance.Logger.error(
'Price is required when creating a product, and must be a string or a number'
'Price is required when creating a product, and must be a string or a number',
ErrorCodes.ECOMMERCE_ERROR
);
return null;
} else {
Expand All @@ -284,7 +292,8 @@ export default function Ecommerce(mpInstance) {

if (position && !mpInstance._Helpers.Validators.isNumber(position)) {
mpInstance.Logger.error(
'Position must be a number, it will be set to null.'
'Position must be a number, it will be set to null.',
ErrorCodes.ECOMMERCE_ERROR
);
position = null;
}
Expand Down Expand Up @@ -312,7 +321,10 @@ export default function Ecommerce(mpInstance) {

this.createPromotion = function(id, creative, name, position) {
if (!mpInstance._Helpers.Validators.isStringOrNumber(id)) {
mpInstance.Logger.error(Messages.ErrorMessages.PromotionIdRequired);
mpInstance.Logger.error(
Messages.ErrorMessages.PromotionIdRequired,
ErrorCodes.ECOMMERCE_ERROR
);
return null;
}

Expand All @@ -327,14 +339,16 @@ export default function Ecommerce(mpInstance) {
this.createImpression = function(name, product) {
if (typeof name !== 'string') {
mpInstance.Logger.error(
'Name is required when creating an impression.'
'Name is required when creating an impression.',
ErrorCodes.ECOMMERCE_ERROR
);
return null;
}

if (!product) {
mpInstance.Logger.error(
'Product is required when creating an impression.'
'Product is required when creating an impression.',
ErrorCodes.ECOMMERCE_ERROR
);
return null;
}
Expand All @@ -355,7 +369,8 @@ export default function Ecommerce(mpInstance) {
) {
if (!mpInstance._Helpers.Validators.isStringOrNumber(id)) {
mpInstance.Logger.error(
Messages.ErrorMessages.TransactionIdRequired
Messages.ErrorMessages.TransactionIdRequired,
ErrorCodes.ECOMMERCE_ERROR
);
return null;
}
Expand Down
19 changes: 14 additions & 5 deletions src/events.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Types from './types';
import Constants from './constants';
import { ErrorCodes } from './logging/errorCodes';

var Messages = Constants.Messages;

Expand Down Expand Up @@ -67,9 +68,10 @@ export default function Events(mpInstance) {
}
} catch (e) {
mpInstance.Logger.error(
'Error invoking the callback passed to startTrackingLocation.'
'Error invoking the callback passed to startTrackingLocation.',
ErrorCodes.EVENTS_ERROR
);
mpInstance.Logger.error(e);
mpInstance.Logger.error(e, ErrorCodes.EVENTS_ERROR);
}
}
}
Expand Down Expand Up @@ -224,7 +226,10 @@ export default function Events(mpInstance) {
customFlags
) {
if (!transactionAttributes) {
mpInstance.Logger.error(Messages.ErrorMessages.TransactionRequired);
mpInstance.Logger.error(
Messages.ErrorMessages.TransactionRequired,
ErrorCodes.EVENTS_ERROR
);
return;
}

Expand Down Expand Up @@ -329,7 +334,8 @@ export default function Events(mpInstance) {
commerceEvent.EventCategory === null
) {
mpInstance.Logger.error(
'Commerce event not sent. The mParticle.ProductActionType you passed was invalid. Re-check your code.'
'Commerce event not sent. The mParticle.ProductActionType you passed was invalid. Re-check your code.',
ErrorCodes.EVENTS_ERROR
);
return;
}
Expand Down Expand Up @@ -414,7 +420,10 @@ export default function Events(mpInstance) {
i;

if (!selector) {
mpInstance.Logger.error("Can't bind event, selector is required");
mpInstance.Logger.error(
"Can't bind event, selector is required",
ErrorCodes.EVENTS_ERROR
);
return;
}

Expand Down
13 changes: 9 additions & 4 deletions src/forwarders.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import APIClient from './apiClient';

const { Modify, Identify, Login, Logout } = Constants.IdentityMethods;

import { ErrorCodes } from './logging/errorCodes';

export default function Forwarders(mpInstance, kitBlocker) {
var self = this;
this.forwarderStatsUploader = new APIClient(
Expand Down Expand Up @@ -443,7 +445,7 @@ export default function Forwarders(mpInstance, kitBlocker) {
mpInstance.Logger.verbose(result);
}
} catch (e) {
mpInstance.Logger.error(e);
mpInstance.Logger.error(e, ErrorCodes.FORWARDERS_ERROR);
}
});
};
Expand Down Expand Up @@ -592,7 +594,8 @@ export default function Forwarders(mpInstance, kitBlocker) {
} catch (e) {
mpInstance.Logger.error(
'MP Kits not configured propertly. Kits may not be initialized. ' +
e
e,
ErrorCodes.FORWARDERS_ERROR
);
}
};
Expand Down Expand Up @@ -702,7 +705,8 @@ export default function Forwarders(mpInstance, kitBlocker) {
} catch (e) {
mpInstance.Logger.error(
'Sideloaded Kits not configured propertly. Kits may not be initialized. ' +
e
e,
ErrorCodes.FORWARDERS_ERROR
);
}
};
Expand Down Expand Up @@ -772,7 +776,8 @@ export default function Forwarders(mpInstance, kitBlocker) {
} catch (e) {
mpInstance.Logger.error(
'Cookie Sync configs not configured propertly. Cookie Sync may not be initialized. ' +
e
e,
ErrorCodes.FORWARDERS_ERROR
);
}
};
Expand Down
Loading
Loading