fixed error logging

This commit is contained in:
Jan Prochazka 2023-01-21 18:00:59 +01:00
parent cc0f05168d
commit d4f0882054
12 changed files with 22 additions and 22 deletions

View File

@ -71,7 +71,7 @@ module.exports = {
...fileType('.matview.sql', 'matview.sql'),
];
} catch (err) {
logger.error('Error reading archive files', err.message);
logger.error({ err }, 'Error reading archive files');
return [];
}
},

View File

@ -54,7 +54,7 @@ function authMiddleware(req, res, next) {
return next();
}
logger.error('Sending invalid token error', err.message);
logger.error({ err }, 'Sending invalid token error');
return unauthorizedResponse(req, res, 'invalid token');
}
@ -125,7 +125,7 @@ module.exports = {
accessToken: jwt.sign({ login }, tokenSecret, { expiresIn: getTokenLifetime() }),
};
} catch (err) {
logger.error('Failed active directory authentization', err);
logger.error({ err }, 'Failed active directory authentization');
return {
error: err.message,
};

View File

@ -347,9 +347,9 @@ function start() {
if (handleProcessCommunication(message)) return;
try {
await handleMessage(message);
} catch (e) {
logger.error('Error in DB connection', e);
process.send({ msgtype: 'error', error: e.message });
} catch (err) {
logger.error({ err }, 'Error in DB connection');
process.send({ msgtype: 'error', error: err.message });
}
});
}

View File

@ -38,7 +38,7 @@ async function handleStart({ connection, tunnelConfig }) {
tunnelConfig,
});
} catch (err) {
logger.error('Error creating SSH tunnel connection:', err);
logger.error({ err }, 'Error creating SSH tunnel connection:');
process.send({
msgtype: 'error',

View File

@ -8,11 +8,11 @@ function childProcessChecker() {
setInterval(() => {
try {
process.send({ msgtype: 'ping', counter: counter++ });
} catch (ex) {
} catch (err) {
// This will come once parent dies.
// One way can be to check for error code ERR_IPC_CHANNEL_CLOSED
// and call process.exit()
logger.error('parent died', ex);
logger.error({ err }, 'parent died');
process.exit(1);
}
}, 1000);

View File

@ -131,8 +131,8 @@ function migrateDataDir() {
if (fs.existsSync(oldDir) && !fs.existsSync(newDir)) {
fs.renameSync(oldDir, newDir);
}
} catch (e) {
logger.error('Error migrating data dir:', e.message);
} catch (err) {
logger.error({ err }, 'Error migrating data dir');
}
}

View File

@ -16,7 +16,7 @@ module.exports = function useController(app, electron, route, controller) {
try {
controller._init();
} catch (err) {
logger.error(`Error initializing controller, exiting application`, err);
logger.error({ err }, `Error initializing controller, exiting application`);
process.exit(1);
}
}
@ -77,16 +77,16 @@ module.exports = function useController(app, electron, route, controller) {
try {
const data = await controller[key]({ ...req.body, ...req.query }, req);
res.json(data);
} catch (e) {
logger.error(`Error when processing route ${route}/${key}`, e);
if (e instanceof MissingCredentialsError) {
} catch (err) {
logger.error({ err }, `Error when processing route ${route}/${key}`);
if (err instanceof MissingCredentialsError) {
res.json({
missingCredentials: true,
apiErrorMessage: 'Missing credentials',
detail: e.detail,
detail: err.detail,
});
} else {
res.status(500).json({ apiErrorMessage: e.message });
res.status(500).json({ apiErrorMessage: err.message });
}
}
});

View File

@ -307,7 +307,7 @@ export class DatabaseAnalyser {
try {
return await this.driver.query(this.pool, sql);
} catch (err) {
logger.error('Error running analyser query', err);
logger.error({ err }, 'Error running analyser query');
return {
rows: [],
};

View File

@ -85,7 +85,7 @@ export class SqlGenerator {
}
private handleException = error => {
logger.error('Unhandled error', error);
logger.error({ error }, 'Unhandled error');
this.isUnhandledException = true;
};

View File

@ -114,7 +114,7 @@ const drivers = driverBases.map(driverBase => ({
};
const handleError = error => {
logger.error('Stream error', error);
logger.error({ error }, 'Stream error');
const { message } = error;
options.info({
message,

View File

@ -147,7 +147,7 @@ const drivers = driverBases.map(driverBase => ({
});
query.on('error', error => {
logger.error('Stream error', error);
logger.error({ error }, 'Stream error');
const { message, position, procName } = error;
let line = null;
if (position) {

View File

@ -106,7 +106,7 @@ const driver = {
try {
inTransaction();
} catch (error) {
logger.error('Stream error', error);
logger.error({ error }, 'Stream error');
const { message, procName } = error;
options.info({
message,