From aa175000e3ba75b65b2cd8c4d9535733233c423f Mon Sep 17 00:00:00 2001 From: Louis Date: Mon, 25 Nov 2024 19:57:40 +0700 Subject: [PATCH 1/3] fix: 3986 - invalid request should show clear error message --- web/containers/ErrorMessage/index.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/web/containers/ErrorMessage/index.tsx b/web/containers/ErrorMessage/index.tsx index be26ad44a..4dc08e54f 100644 --- a/web/containers/ErrorMessage/index.tsx +++ b/web/containers/ErrorMessage/index.tsx @@ -29,7 +29,6 @@ const ErrorMessage = ({ message }: { message: ThreadMessage }) => { switch (message.error_code) { case ErrorCode.InvalidApiKey: case ErrorCode.AuthenticationError: - case ErrorCode.InvalidRequestError: return ( Invalid API key. Please check your API key from{' '} From f227d35238397c673a51e5fa72ab4e2a4d2125b8 Mon Sep 17 00:00:00 2001 From: Louis Date: Mon, 25 Nov 2024 21:21:11 +0700 Subject: [PATCH 2/3] test: update test case --- electron/tests/e2e/thread.e2e.spec.ts | 4 +++- web/containers/ErrorMessage/index.test.tsx | 6 +++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/electron/tests/e2e/thread.e2e.spec.ts b/electron/tests/e2e/thread.e2e.spec.ts index 5d7328053..75b90dc39 100644 --- a/electron/tests/e2e/thread.e2e.spec.ts +++ b/electron/tests/e2e/thread.e2e.spec.ts @@ -25,7 +25,9 @@ test('Select GPT model from Hub and Chat with Invalid API Key', async ({ { timeout: TIMEOUT } ) - const APIKeyError = page.getByTestId('invalid-API-key-error') + const APIKeyError = page.getByText( + `You didn't provide an API key. You need to provide your API key in an Authorization header using Bearer auth (i.e. Authorization: Bearer YOUR_KEY), or as the password field (with blank username) if you're accessing the API from your browser and are prompted for a username and password. You can obtain an API key from https://platform.openai.com/account/api-keys.` + ) await expect(APIKeyError).toBeVisible({ timeout: TIMEOUT, }) diff --git a/web/containers/ErrorMessage/index.test.tsx b/web/containers/ErrorMessage/index.test.tsx index 306a80e32..1ebb713fa 100644 --- a/web/containers/ErrorMessage/index.test.tsx +++ b/web/containers/ErrorMessage/index.test.tsx @@ -49,7 +49,11 @@ describe('ErrorMessage Component', () => { render() - expect(screen.getByTestId('invalid-API-key-error')).toBeInTheDocument() + expect( + screen.getByText( + `You didn't provide an API key. You need to provide your API key in an Authorization header using Bearer auth (i.e. Authorization: Bearer YOUR_KEY), or as the password field (with blank username) if you're accessing the API from your browser and are prompted for a username and password. You can obtain an API key from https://platform.openai.com/account/api-keys.` + ) + ).toBeInTheDocument() expect(screen.getByText('Settings')).toBeInTheDocument() }) From 60a888c9d7d526e316d19c331d12376ac2330379 Mon Sep 17 00:00:00 2001 From: Louis Date: Tue, 26 Nov 2024 11:07:43 +0700 Subject: [PATCH 3/3] test: correct test case --- electron/tests/e2e/thread.e2e.spec.ts | 4 +--- web/containers/ErrorMessage/index.test.tsx | 6 +----- web/containers/ErrorMessage/index.tsx | 2 +- 3 files changed, 3 insertions(+), 9 deletions(-) diff --git a/electron/tests/e2e/thread.e2e.spec.ts b/electron/tests/e2e/thread.e2e.spec.ts index 75b90dc39..dfd131988 100644 --- a/electron/tests/e2e/thread.e2e.spec.ts +++ b/electron/tests/e2e/thread.e2e.spec.ts @@ -25,9 +25,7 @@ test('Select GPT model from Hub and Chat with Invalid API Key', async ({ { timeout: TIMEOUT } ) - const APIKeyError = page.getByText( - `You didn't provide an API key. You need to provide your API key in an Authorization header using Bearer auth (i.e. Authorization: Bearer YOUR_KEY), or as the password field (with blank username) if you're accessing the API from your browser and are prompted for a username and password. You can obtain an API key from https://platform.openai.com/account/api-keys.` - ) + const APIKeyError = page.getByTestId('passthrough-error-message') await expect(APIKeyError).toBeVisible({ timeout: TIMEOUT, }) diff --git a/web/containers/ErrorMessage/index.test.tsx b/web/containers/ErrorMessage/index.test.tsx index 1ebb713fa..306a80e32 100644 --- a/web/containers/ErrorMessage/index.test.tsx +++ b/web/containers/ErrorMessage/index.test.tsx @@ -49,11 +49,7 @@ describe('ErrorMessage Component', () => { render() - expect( - screen.getByText( - `You didn't provide an API key. You need to provide your API key in an Authorization header using Bearer auth (i.e. Authorization: Bearer YOUR_KEY), or as the password field (with blank username) if you're accessing the API from your browser and are prompted for a username and password. You can obtain an API key from https://platform.openai.com/account/api-keys.` - ) - ).toBeInTheDocument() + expect(screen.getByTestId('invalid-API-key-error')).toBeInTheDocument() expect(screen.getByText('Settings')).toBeInTheDocument() }) diff --git a/web/containers/ErrorMessage/index.tsx b/web/containers/ErrorMessage/index.tsx index 4dc08e54f..532f02259 100644 --- a/web/containers/ErrorMessage/index.tsx +++ b/web/containers/ErrorMessage/index.tsx @@ -52,7 +52,7 @@ const ErrorMessage = ({ message }: { message: ThreadMessage }) => { ) default: return ( -

+

{message.content[0]?.text?.value && ( )}