From 5369cb14a5c963aa63070a00b366710d8b40ad69 Mon Sep 17 00:00:00 2001 From: munimunigamer Date: Mon, 29 Dec 2025 02:42:37 -1200 Subject: [PATCH] add cors error logging, letting the user know if an endpoint can't be used due to cors blocking --- src/systems/generation/apiClient.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/systems/generation/apiClient.js b/src/systems/generation/apiClient.js index fabdee3..894997b 100644 --- a/src/systems/generation/apiClient.js +++ b/src/systems/generation/apiClient.js @@ -101,8 +101,8 @@ export async function generateWithExternalAPI(messages) { return content; } catch (error) { - if (error.name === 'TypeError' && error.message.includes('fetch')) { - throw new Error(`Failed to connect to external API. Check the URL and your network connection.`); + if (error.name === 'TypeError' && (error.message.includes('fetch') || error.message.includes('Failed to fetch') || error.message.includes('NetworkError'))) { + throw new Error(`CORS Access Blocked: This API endpoint (${normalizedBaseUrl}) does not allow direct access from a browser. This is a browser security restriction (CORS), not a bug in the extension. Please use an endpoint that supports CORS (like OpenRouter or a local proxy) or use SillyTavern's internal API system (Separate Mode).`); } throw error; } @@ -368,6 +368,9 @@ export async function updateRPGData(renderUserStats, renderInfoBox, renderThough } catch (error) { console.error('[RPG Companion] Error updating RPG data:', error); + if (isExternalMode) { + toastr.error(error.message, 'RPG Companion External API Error'); + } } finally { // Restore original preset if we switched to a separate one if (originalPresetName && extensionSettings.useSeparatePreset) {