Skip to content

Commit

Permalink
fix: address ai bot review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
saikumarrs committed Feb 21, 2025
1 parent 9cafb17 commit 571a542
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ describe('CookieStorage', () => {
// engine.clear();
// expect(engine.length).toStrictEqual(0);
});

it('should not set domain if sameDomainCookiesOnly is set to true', () => {
expect(typeof engine.options.domain).toBe('string');
configureCookieStorageEngine({
Expand All @@ -43,4 +44,18 @@ describe('CookieStorage', () => {
const newEngine = getStorageEngine('cookieStorage');
expect(newEngine.options.domain).toBe(undefined);
});

it('should properly configure cookie attributes', () => {
configureCookieStorageEngine({
samesite: 'Strict',
secure: true,
path: '/app',
maxage: 3600000,
});
const newEngine = getStorageEngine('cookieStorage');
expect(newEngine.options.samesite).toBe('Strict');
expect(newEngine.options.secure).toBe(true);
expect(newEngine.options.path).toBe('/app');
expect(newEngine.options.maxage).toBe(3600000);
});
});
20 changes: 20 additions & 0 deletions packages/analytics-js/src/services/ErrorHandler/ErrorHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,30 @@ import {
class ErrorHandler implements IErrorHandler {
httpClient: IHttpClient;
logger: ILogger;
private initialized = false;

// If no logger is passed errors will be thrown as unhandled error
constructor(httpClient: IHttpClient, logger: ILogger) {
this.httpClient = httpClient;
this.logger = logger;
}

/**
* Initializes the error handler by attaching global error listeners.
* This method should be called once after construction.
*/
init() {
if (this.initialized) {
return;
}

this.attachErrorListeners();
this.initialized = true;
}

/**
* Attach error listeners to the global window object
*/
attachErrorListeners() {
(globalThis as typeof window).addEventListener('error', (event: ErrorEvent | Event) => {
this.onError(event, ERROR_HANDLER, undefined, ErrorType.UNHANDLEDEXCEPTION);
Expand All @@ -57,6 +70,13 @@ class ErrorHandler implements IErrorHandler {
);
}

/**
* Handle errors
* @param error - The error to handle
* @param context - The context of where the error occurred
* @param customMessage - The custom message of the error
* @param errorType - The type of the error (handled or unhandled)
*/
onError(
error: SDKError,
context = '',
Expand Down

0 comments on commit 571a542

Please sign in to comment.