Error logging with stack trace

This commit is contained in:
La Programmatrice Verde 2025-08-25 10:55:20 +02:00
parent 407a428795
commit da58b9c573
2 changed files with 40 additions and 23 deletions

View File

@ -42,12 +42,14 @@ async function isConnected(hostID) {
);
Log(`[${shared.now()}] ${hostID} connected: ${response.data.connected}`);
return response.data.connected;
}
catch (error) {
} catch (error) {
Log(
`[${shared.now()}] Errore nella verifica dello stato per l'host ${hostID}`
);
Log(`[${shared.now()}] ${error}`);
Log(`[${shared.now()}] Errore nella verifica dello stato per l'host ${hostID}`);
Log(`[${shared.now()}] Debug: ${error.stack}`);
process.exit(3);
}
}
}
async function initHostList() {
@ -78,8 +80,10 @@ async function initHostList() {
});
} catch (error) {
Log(
`[${shared.now()}] Errore nella verifica e aggiunta al monitoraggio di un host: ${error}`
`[${shared.now()}] Errore nella verifica e aggiunta al monitoraggio di un host.`
);
Log(`[${shared.now()}] ${error}`);
Log(`[${shared.now()}] Debug: ${error.stack}`);
process.exit(3);
}
}
@ -97,8 +101,10 @@ async function initHostList() {
hostIDs.push(response.data[0].id);
} catch (error) {
Log(
`[${shared.now()}] Errore nella verifica e aggiunta al monitoraggio di un host: ${error}`
`[${shared.now()}] Errore nella verifica e aggiunta al monitoraggio di un host.`
);
Log(`[${shared.now()}] ${error}`);
Log(`[${shared.now()}] Debug: ${error.stack}`);
process.exit(3);
}
}
@ -124,8 +130,10 @@ async function initHostList() {
hostIDs.push(response.data.id);
} catch (error) {
Log(
`[${shared.now()}] Errore nella verifica e aggiunta al monitoraggio di un host: ${error}`
`[${shared.now()}] Errore nella verifica e aggiunta al monitoraggio di un host.`
);
Log(`[${shared.now()}] ${error}`);
Log(`[${shared.now()}] Debug: ${error.stack}`);
process.exit(3);
}
}
@ -143,8 +151,10 @@ async function initHostList() {
hostIDs.push(response.data.id);
} catch (error) {
Log(
`[${shared.now()}] Errore nella verifica e aggiunta al monitoraggio di un host: ${error}`
`[${shared.now()}] Errore nella verifica e aggiunta al monitoraggio di un host.`
);
Log(`[${shared.now()}] ${error}`);
Log(`[${shared.now()}] Debug: ${error.stack}`);
process.exit(3);
}
}
@ -164,8 +174,9 @@ async function initHostList() {
hostIDs.push(element.id);
});
} catch (error) {
Log(`[${shared.now()}] Errore nel tentativo di reperire tutti i peer.`);
Log(`[${shared.now()}] ${error}`);
Log(`[${shared.now()}] Errore nel tentativo di reperire tutti i peer`);
Log(`[${shared.now()}] Debug: ${error.stack}`);
process.exit(3);
}
}

View File

@ -7,19 +7,19 @@ let userID;
async function TokenRenew() {
setInterval(async () => {
shared.eventEmitter.emit("tokenRenewalStart");
// ottieni l'ID dell'utente associato al token
userID = await getUserID();
// ottieni l'ID dell'utente associato al token
userID = await getUserID();
// ottieni l'ID del token corrente
const tokenID = await getCurrentTokenID();
// ottieni l'ID del token corrente
const tokenID = await getCurrentTokenID();
// crea nuovo token
const newToken = await getNewToken();
shared.setToken(newToken);
// crea nuovo token
const newToken = await getNewToken();
shared.setToken(newToken);
// cancella il token precedente
await deleteToken(tokenID);
shared.eventEmitter.emit("tokenRenewalEnd");
// cancella il token precedente
await deleteToken(tokenID);
shared.eventEmitter.emit("tokenRenewalEnd");
}, day - hour);
}
@ -37,8 +37,9 @@ async function getUserID() {
Log(`[${shared.now()}] UserID: ${response.data.id}`);
return response.data.id;
} catch (error) {
Log(`[${shared.now()}] Errore nel reperire l'ID dell'utente corrente.`);
Log(`[${shared.now()}] ${error}`);
Log(`[${shared.now()}] Errore nel reperire l'ID dell'utente corrente`);
Log(`[${shared.now()}] Debug: ${error.stack}`);
process.exit(3);
}
}
@ -55,8 +56,11 @@ async function deleteToken(tokenID) {
);
Log(`[${shared.now()}] Token con ID ${tokenID} cancellato con successo`);
} catch (error) {
Log(
`[${shared.now()}] Errore nella cancellazione del token con ID ${tokenID}.`
);
Log(`[${shared.now()}] ${error}`);
Log(`[${shared.now()}] Errore nella cancellazione del token con ID ${tokenID}`);
Log(`[${shared.now()}] Debug: ${error.stack}`);
process.exit(3);
}
}
@ -79,8 +83,9 @@ async function getCurrentTokenID() {
Log(`[${shared.now()}] CurrentTokenID: ${token.id}`);
return token.id;
} catch (error) {
Log(`[${shared.now()}] Errore nel reperire il token corrente.`);
Log(`[${shared.now()}] ${error}`);
Log(`[${shared.now()}] Errore nel reperire il token corrente`);
Log(`[${shared.now()}] Debug: ${error.stack}`);
process.exit(3);
}
}
@ -104,8 +109,9 @@ async function getNewToken() {
Log(`[${shared.now()}] Nuovo token creato: ${response.data.plain_token}`);
return response.data.plain_token;
} catch (error) {
Log(`[${shared.now()}] Errore nella creazione di un nuovo token.`);
Log(`[${shared.now()}] ${error}`);
Log(`[${shared.now()}] Errore nella creazione di un nuovo token`);
Log(`[${shared.now()}] Debug: ${error.stack}`);
process.exit(3);
}
}