Fix: add extended wait loop for Matrix User ID resolution (30s timeout)
This commit is contained in:
12
index.js
12
index.js
@@ -49,16 +49,14 @@ function loadQuotes() {
|
||||
await client.startClient();
|
||||
console.log('✅ MatrixClient connected and authenticated\n');
|
||||
|
||||
// The M_INVALID_PARAM error often happens if we try to access properties
|
||||
// before the user profile is fully loaded.
|
||||
// Let's wait for the user identity to be available.
|
||||
console.log('⏳ Waiting for User Identity to resolve...');
|
||||
let attempts = 0;
|
||||
while (!client.user || !client.user.userId) {
|
||||
if (attempts > 15) {
|
||||
throw new Error('Timeout waiting for Matrix UserID resolution.');
|
||||
if (attempts > 30) {
|
||||
throw new Error('Timeout waiting for Matrix User ID resolution (30s).');
|
||||
}
|
||||
console.log(`⏳ Waiting for User ID (Attempt ${attempts + 1})...`);
|
||||
await new Promise(resolve => setTimeout(resolve, 2000));
|
||||
console.log(` ... Waiting for UserID (Attempt ${attempts + 1})`);
|
||||
await new Promise(resolve => setTimeout(resolve, 1000));
|
||||
attempts++;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user