From 31b9c6972856514b7023e7d46414404fe0fed633 Mon Sep 17 00:00:00 2001 From: Bsian Date: Sun, 17 Nov 2019 01:46:55 +0000 Subject: [PATCH] SecureSign hash error handler --- src/functions/checkSS.ts | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/src/functions/checkSS.ts b/src/functions/checkSS.ts index ee4bd6d..751b95c 100644 --- a/src/functions/checkSS.ts +++ b/src/functions/checkSS.ts @@ -4,22 +4,26 @@ import { Client } from '..'; export default function checkSS(client: Client) { setInterval(async () => { - const accounts = await client.db.Account.find(); - const hashes = accounts.filter((h) => h.hash); - for (const { hash, userID } of hashes) { - try { - await axios({ - method: 'get', - url: 'https://api.securesign.org/account/details', - headers: { Authorization: hash }, - }); - } catch (error) { - const { status } = error.response; - if (status === 400 || status === 401 || status === 403 || status === 404) { - client.db.Account.updateOne({ hash }, { $set: { hash: null } }); - client.getDMChannel(userID).then((channel) => channel.createMessage('Your SecureSign password has been reset - please reinitialize your SecureSign account')).catch(); + try { + const accounts = await client.db.Account.find(); + const hashes = accounts.filter((h) => h.hash); + for (const { hash, userID } of hashes) { + try { + await axios({ + method: 'get', + url: 'https://api.securesign.org/account/details', + headers: { Authorization: hash }, + }); + } catch (error) { + const { status } = error.response; + if (status === 400 || status === 401 || status === 403 || status === 404) { + client.db.Account.updateOne({ hash }, { $set: { hash: null } }); + client.getDMChannel(userID).then((channel) => channel.createMessage('Your SecureSign password has been reset - please reinitialize your SecureSign account')).catch(); + } } } + } catch (error) { + client.util.handleError(error); } }, 60000); }