Skip to content

armgit / jan

Public Imported from GitHub
0

Jan is an open source alternative to ChatGPT that runs 100% offline on your computer.

refactor: more modular error handling in fetchModelsFromProvider function

lugnicca9a68631d39ff
diff --git a/web-app/src/services/providers.ts b/web-app/src/services/providers.ts
index 748aed322..a036c9148 100644
--- a/web-app/src/services/providers.ts
+++ b/web-app/src/services/providers.ts
@@ -182,13 +182,16 @@ export const fetchModelsFromProvider = async (
} catch (error) {
console.error('Error fetching models from provider:', error)
- if (error instanceof Error && (
- error.message.includes('Authentication failed') ||
- error.message.includes('Access forbidden') ||
- error.message.includes('Models endpoint not found') ||
- error.message.includes('Failed to fetch models from')
- )) {
- throw error
+ const structuredErrorPrefixes = [
+ 'Authentication failed',
+ 'Access forbidden',
+ 'Models endpoint not found',
+ 'Failed to fetch models from'
+ ]
+
+ if (error instanceof Error &&
+ structuredErrorPrefixes.some(prefix => (error as Error).message.startsWith(prefix))) {
+ throw new Error(error.message)
}
// Provide helpful error message for network issues