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

View File

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