feat: enhance error handling for network-related issues in JMAPClient and auth-store #100
This commit is contained in:
+6
-1
@@ -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' });
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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'] },
|
||||
];
|
||||
|
||||
|
||||
Reference in New Issue
Block a user