fix: new URL should always be in a try block

This commit is contained in:
Simon
2026-07-03 20:14:11 +08:00
parent 5aeb67f6d6
commit 10276c6e67
+8 -4
View File
@@ -209,8 +209,12 @@ export function normalizeModelName(modelName: string): string {
export function getProvider(baseURL?: string): 'openrouter' | undefined { export function getProvider(baseURL?: string): 'openrouter' | undefined {
if (!baseURL) return undefined if (!baseURL) return undefined
const url = new URL(baseURL) try {
const hostname = url.hostname const url = new URL(baseURL)
if (hostname === 'openrouter.ai') return 'openrouter' const hostname = url.hostname
return undefined if (hostname === 'openrouter.ai') return 'openrouter'
return undefined
} catch (e) {
return undefined
}
} }