fix(nitter): error handling
This commit is contained in:
parent
751dbb335f
commit
d7396b8786
1 changed files with 4 additions and 5 deletions
|
@ -50,14 +50,13 @@ const run = async (matrixClient, { roomId }, userInput, registrar) => {
|
||||||
return await matrixClient.sendHtmlNotice(roomId, '', card(tweet, `https://${config.domain}`, userInput));
|
return await matrixClient.sendHtmlNotice(roomId, '', card(tweet, `https://${config.domain}`, userInput));
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.runQuery = (client, room, userInput, registrar) => {
|
exports.runQuery = async (client, room, userInput, registrar) => {
|
||||||
let url = null;
|
|
||||||
try {
|
try {
|
||||||
url = new URL(userInput);
|
const url = new URL(userInput);
|
||||||
if(!registrar.config.nitter.domains.includes(url.hostname)) throw '';
|
if(!registrar.config.nitter.domains.includes(url.hostname)) throw '';
|
||||||
if(!/^\/[^/]+\/status\/\d+\/?$/.test(url.pathname)) throw '';
|
if(!/^\/[^/]+\/status\/\d+\/?$/.test(url.pathname)) throw '';
|
||||||
|
return await run(client, room, url.pathname, registrar);
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
return client.sendHtmlNotice(roomId, 'Sad!', `<strong>Sad!</strong>`).catch(()=>{});
|
return client.sendHtmlNotice(room.roomId, 'Sad!', `<strong>Sad!</strong>`).catch(()=>{});
|
||||||
}
|
}
|
||||||
return run(client, room, url.pathname, registrar);
|
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue