feat: detect CORS errors and show actionable guidance on login
Distinguish CORS-blocked requests from genuine network failures using a no-cors probe, so users deploying via Docker see a specific message pointing to their JMAP server's CORS settings instead of a misleading "unable to reach the server" error.
This commit is contained in:
+10
-1
@@ -133,7 +133,16 @@ export class JMAPClient {
|
||||
// Start keep-alive mechanism
|
||||
this.startKeepAlive();
|
||||
} catch (error) {
|
||||
console.error('Connection failed:', error);
|
||||
if (error instanceof TypeError && (error.message === 'Failed to fetch' || error.message.includes('NetworkError'))) {
|
||||
let serverReachable = false;
|
||||
try {
|
||||
await fetch(sessionUrl, { mode: 'no-cors' });
|
||||
serverReachable = true;
|
||||
} catch { /* genuinely unreachable */ }
|
||||
if (serverReachable) {
|
||||
throw new Error('CORS_ERROR');
|
||||
}
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user