Use safe instead of try/catch

This commit is contained in:
Girish Ramakrishnan
2021-09-01 15:29:35 -07:00
parent 8d43015867
commit 167eae5b81
2 changed files with 12 additions and 25 deletions

View File

@@ -101,14 +101,9 @@ async function add(action, source, data) {
assert.strictEqual(typeof data, 'object');
const id = uuid.v4();
try {
await database.query('INSERT INTO eventlog (id, action, source, data) VALUES (?, ?, ?, ?)', [ id, action, JSON.stringify(source), JSON.stringify(data) ]);
await notifications.onEvent(id, action, source, data);
return id;
} catch (error) {
debug('add: error adding event', error);
return null;
}
await database.query('INSERT INTO eventlog (id, action, source, data) VALUES (?, ?, ?, ?)', [ id, action, JSON.stringify(source), JSON.stringify(data) ]);
await notifications.onEvent(id, action, source, data);
return id;
}
// never throws, only logs because previously code did not take a callback
@@ -126,16 +121,11 @@ async function upsertLoginEvent(action, source, data) {
args: [ action, JSON.stringify(source) ]
}];
try {
const result = await database.transaction(queries);
if (result[0].affectedRows >= 1) return result[1][0].id;
const result = await database.transaction(queries);
if (result[0].affectedRows >= 1) return result[1][0].id;
// no existing eventlog found, create one
return await add(action, source, data);
} catch (error) {
debug('add: error adding event', error);
return null;
}
// no existing eventlog found, create one
return await add(action, source, data);
}
async function get(id) {