From f67a9dd3d7cbd293fae86406a644e32b1669efd5 Mon Sep 17 00:00:00 2001 From: Walden Bodtker Date: Wed, 2 Apr 2025 09:14:18 -0700 Subject: [PATCH 1/2] update auth messsaging --- quotientai/index.ts | 17 +++++++++++++---- tests/index.test.ts | 20 ++++++++++++++++++++ 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/quotientai/index.ts b/quotientai/index.ts index 074e144..4c1cbcb 100644 --- a/quotientai/index.ts +++ b/quotientai/index.ts @@ -37,7 +37,7 @@ export class QuotientAI { } } - private initializeResources(client: BaseQuotientClient): void { + private initializeResources(client: BaseQuotientClient): void { // Initialize resources this.auth = new AuthResource(client); this.prompts = new PromptsResource(client); @@ -47,11 +47,20 @@ export class QuotientAI { this.metrics = new MetricsResource(client); this.logs = new LogsResource(client); - // Authenticate - this.auth.authenticate(); - // Create an unconfigured logger instance this.logger = new QuotientLogger(this.logs as LogsResource); + + // Authenticate + try { + this.auth.authenticate(); + } catch (error) { + logError( + error as Error, + 'If you are seeing this error, please check that your API key is correct and that you have access to the QuotientAI API.\n' + + 'If the issue persists, please contact support@quotientai.co' + ); + return; + } } async evaluate(params: { diff --git a/tests/index.test.ts b/tests/index.test.ts index 61d608f..8f8c5b3 100644 --- a/tests/index.test.ts +++ b/tests/index.test.ts @@ -145,4 +145,24 @@ describe('QuotientAI', () => { metrics: ['test_metric'] }); }); + + it('should handle authentication errors during initialization', () => { + // Mock the authenticate method to throw an error + const error = new Error('Authentication failed'); + mockAuthenticate.mockImplementationOnce(() => { + throw error; + }); + + // Spy on console.error + const consoleErrorSpy = vi.spyOn(console, 'error').mockImplementation(() => {}); + + // Create a new instance + const quotient = new QuotientAI('test_api_key'); + + // Verify error was logged with correct message + expect(consoleErrorSpy).toHaveBeenCalledWith( + expect.stringContaining('If you are seeing this error, please check that your API key is correct and that you have access to the QuotientAI API') + ); + expect(quotient).toBeDefined(); + }); }); From 069a304f68206be73e0e76ce19f4c54b60c48994 Mon Sep 17 00:00:00 2001 From: Walden Bodtker Date: Wed, 2 Apr 2025 10:09:45 -0700 Subject: [PATCH 2/2] update messaging --- quotientai/index.ts | 2 +- tests/index.test.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/quotientai/index.ts b/quotientai/index.ts index 4c1cbcb..ad0d909 100644 --- a/quotientai/index.ts +++ b/quotientai/index.ts @@ -56,7 +56,7 @@ export class QuotientAI { } catch (error) { logError( error as Error, - 'If you are seeing this error, please check that your API key is correct and that you have access to the QuotientAI API.\n' + + 'If you are seeing this error, please check that your API key is correct.\n' + 'If the issue persists, please contact support@quotientai.co' ); return; diff --git a/tests/index.test.ts b/tests/index.test.ts index 8f8c5b3..c063c73 100644 --- a/tests/index.test.ts +++ b/tests/index.test.ts @@ -161,7 +161,7 @@ describe('QuotientAI', () => { // Verify error was logged with correct message expect(consoleErrorSpy).toHaveBeenCalledWith( - expect.stringContaining('If you are seeing this error, please check that your API key is correct and that you have access to the QuotientAI API') + expect.stringContaining('If you are seeing this error, please check that your API key is correct.') ); expect(quotient).toBeDefined(); });