Use safe instead of try/catch
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user