Skip to content

Commit fd0b9d0

Browse files
committed
Improve Matrix media error handling for HTTP2 protocol issues
- Enhanced getAuthenticatedMediaBlob with timeout and better error handling - Added specific handling for HTTP2 protocol errors and timeouts - Improved error messages to distinguish between different failure types - Added 10-second timeout to prevent hanging requests This addresses the 'net::ERR_HTTP2_PROTOCOL_ERROR' errors when fetching Matrix user avatars and other media from the Matrix server.
1 parent d4aebaf commit fd0b9d0

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

ui/desktop/src/services/MatrixService.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1120,11 +1120,13 @@ export class MatrixService extends EventEmitter {
11201120
return null;
11211121
}
11221122

1123-
// Fetch with authentication header
1123+
// Fetch with authentication header and improved error handling
11241124
const response = await fetch(httpUrl, {
11251125
headers: {
11261126
'Authorization': `Bearer ${accessToken}`,
11271127
},
1128+
// Add timeout and other fetch options to handle HTTP2 issues
1129+
signal: AbortSignal.timeout(10000), // 10 second timeout
11281130
});
11291131

11301132
if (!response.ok) {
@@ -1139,7 +1141,20 @@ export class MatrixService extends EventEmitter {
11391141
console.log('getAuthenticatedMediaBlob - created blob URL:', blobUrl);
11401142
return blobUrl;
11411143
} catch (error) {
1142-
console.error('Failed to get authenticated media blob:', error);
1144+
// Enhanced error handling for different types of network errors
1145+
if (error instanceof Error) {
1146+
if (error.name === 'TimeoutError') {
1147+
console.warn('Matrix media fetch timed out for:', mxcUrl);
1148+
} else if (error.message.includes('HTTP2') || error.message.includes('PROTOCOL_ERROR')) {
1149+
console.warn('HTTP2 protocol error fetching Matrix media:', mxcUrl, '- this is usually a server-side issue');
1150+
} else if (error.message.includes('Failed to fetch')) {
1151+
console.warn('Network error fetching Matrix media:', mxcUrl, '- check network connection');
1152+
} else {
1153+
console.error('Failed to get authenticated media blob:', error);
1154+
}
1155+
} else {
1156+
console.error('Failed to get authenticated media blob:', error);
1157+
}
11431158
return null;
11441159
}
11451160
}

0 commit comments

Comments
 (0)