add cors error logging, letting the user know if an endpoint can't be used due to cors blocking

This commit is contained in:
munimunigamer
2025-12-29 02:42:37 -12:00
parent 1d4a64bac7
commit 5369cb14a5
+5 -2
View File
@@ -101,8 +101,8 @@ export async function generateWithExternalAPI(messages) {
return content; return content;
} catch (error) { } catch (error) {
if (error.name === 'TypeError' && error.message.includes('fetch')) { if (error.name === 'TypeError' && (error.message.includes('fetch') || error.message.includes('Failed to fetch') || error.message.includes('NetworkError'))) {
throw new Error(`Failed to connect to external API. Check the URL and your network connection.`); 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; throw error;
} }
@@ -368,6 +368,9 @@ export async function updateRPGData(renderUserStats, renderInfoBox, renderThough
} catch (error) { } catch (error) {
console.error('[RPG Companion] Error updating RPG data:', error); console.error('[RPG Companion] Error updating RPG data:', error);
if (isExternalMode) {
toastr.error(error.message, 'RPG Companion External API Error');
}
} finally { } finally {
// Restore original preset if we switched to a separate one // Restore original preset if we switched to a separate one
if (originalPresetName && extensionSettings.useSeparatePreset) { if (originalPresetName && extensionSettings.useSeparatePreset) {