Skip to content
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
17 changes: 13 additions & 4 deletions quotientai/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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.\n' +
'If the issue persists, please contact support@quotientai.co'
);
return;
}
}

async evaluate(params: {
Expand Down
20 changes: 20 additions & 0 deletions tests/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.')
);
expect(quotient).toBeDefined();
});
});