From c3d631ca98e2991469f0293124e166fa09852c27 Mon Sep 17 00:00:00 2001 From: "Taylor Wilsdon (aider)" Date: Sun, 15 Dec 2024 16:55:04 -0500 Subject: [PATCH] fix: Improve Google Drive API credentials validation and error handling --- src/lib/components/chat/MessageInput.svelte | 7 +++---- src/lib/utils/google-drive-picker.ts | 5 ++++- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/lib/components/chat/MessageInput.svelte b/src/lib/components/chat/MessageInput.svelte index 092c214e8..e1ce85e64 100644 --- a/src/lib/components/chat/MessageInput.svelte +++ b/src/lib/components/chat/MessageInput.svelte @@ -499,16 +499,15 @@ }} uploadGoogleDriveHandler={async () => { try { - if (!import.meta.env.VITE_GOOGLE_API_KEY || !import.meta.env.VITE_GOOGLE_CLIENT_ID) { - throw new Error('Google Drive API credentials not configured'); - } const fileData = await createPicker(); if (fileData) { dispatch('upload', { type: 'google-drive', data: fileData }); } } catch (error) { console.error('Google Drive Error:', error); - toast.error('Error accessing Google Drive: ' + error.message); + toast.error($i18n.t('Error accessing Google Drive: {{error}}', { + error: error.message + })); } }} onClose={async () => { diff --git a/src/lib/utils/google-drive-picker.ts b/src/lib/utils/google-drive-picker.ts index 62726bec8..c96771cb8 100644 --- a/src/lib/utils/google-drive-picker.ts +++ b/src/lib/utils/google-drive-picker.ts @@ -6,7 +6,10 @@ const SCOPE = ['https://www.googleapis.com/auth/drive.readonly']; // Validate required credentials const validateCredentials = () => { if (!API_KEY || !CLIENT_ID) { - throw new Error('Google Drive API credentials not configured. Please set VITE_GOOGLE_API_KEY and VITE_GOOGLE_CLIENT_ID environment variables.'); + throw new Error('Google Drive API credentials not configured'); + } + if (API_KEY === 'your-api-key' || CLIENT_ID === 'your-client-id') { + throw new Error('Please configure valid Google Drive API credentials'); } };