feat: enhance error handling for network-related issues in JMAPClient and auth-store #100

This commit is contained in:
Linus Rath
2026-03-26 13:04:34 +01:00
parent 47918aab1b
commit 4ff2bff974
3 changed files with 8 additions and 3 deletions
+6 -1
View File
@@ -250,7 +250,12 @@ export class JMAPClient implements IJMAPClient {
this.startKeepAlive();
} catch (error) {
if (error instanceof TypeError && (error.message === 'Failed to fetch' || error.message.includes('NetworkError'))) {
if (error instanceof TypeError && (
error.message === 'Failed to fetch' ||
error.message.includes('NetworkError') ||
error.message === 'Load failed' ||
error.message === 'cancelled'
)) {
let serverReachable = false;
try {
await fetch(sessionUrl, { mode: 'no-cors' });
+1 -1
View File
@@ -3,7 +3,7 @@ const COOKIE_SAME_SITE = (process.env.COOKIE_SAME_SITE || 'lax') as 'lax' | 'non
export function getCookieOptions() {
return {
httpOnly: true,
secure: COOKIE_SAME_SITE === 'none' ? true : process.env.NODE_ENV === 'production',
secure: COOKIE_SAME_SITE === 'none' || process.env.NODE_ENV === 'production',
sameSite: COOKIE_SAME_SITE,
path: '/',
maxAge: 30 * 24 * 60 * 60,
+1 -1
View File
@@ -51,7 +51,7 @@ interface AuthState {
const ERROR_PATTERNS: Array<{ key: string; matches: string[] }> = [
{ key: 'cors_blocked', matches: ['CORS_ERROR'] },
{ key: 'invalid_credentials', matches: ['Invalid username or password', '401', 'Unauthorized'] },
{ key: 'connection_failed', matches: ['network', 'Failed to fetch', 'NetworkError', 'ECONNREFUSED'] },
{ key: 'connection_failed', matches: ['network', 'Failed to fetch', 'NetworkError', 'ECONNREFUSED', 'Load failed', 'cancelled'] },
{ key: 'server_error', matches: ['500', '502', '503', '504', 'Internal Server Error', 'Service Unavailable'] },
];