SecureSign hash error handler

merge-requests/1/merge
Bsian 2019-11-17 01:46:55 +00:00
parent 3ec1e03e27
commit 31b9c69728
No known key found for this signature in database
GPG Key ID: 097FB9A291026091
1 changed files with 18 additions and 14 deletions

View File

@ -4,22 +4,26 @@ import { Client } from '..';
export default function checkSS(client: Client) { export default function checkSS(client: Client) {
setInterval(async () => { setInterval(async () => {
const accounts = await client.db.Account.find(); try {
const hashes = accounts.filter((h) => h.hash); const accounts = await client.db.Account.find();
for (const { hash, userID } of hashes) { const hashes = accounts.filter((h) => h.hash);
try { for (const { hash, userID } of hashes) {
await axios({ try {
method: 'get', await axios({
url: 'https://api.securesign.org/account/details', method: 'get',
headers: { Authorization: hash }, url: 'https://api.securesign.org/account/details',
}); headers: { Authorization: hash },
} catch (error) { });
const { status } = error.response; } catch (error) {
if (status === 400 || status === 401 || status === 403 || status === 404) { const { status } = error.response;
client.db.Account.updateOne({ hash }, { $set: { hash: null } }); if (status === 400 || status === 401 || status === 403 || status === 404) {
client.getDMChannel(userID).then((channel) => channel.createMessage('Your SecureSign password has been reset - please reinitialize your SecureSign account')).catch(); 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); }, 60000);
} }