1
0
mirror of https://github.com/matt-fidd/stratos.git synced 2026-01-01 17:59:25 +00:00

Catch database errors and prevent them from crashing the app

This commit is contained in:
2022-03-21 09:12:48 +00:00
parent 0298c81f51
commit e34016667f
4 changed files with 35 additions and 11 deletions

View File

@@ -98,11 +98,20 @@ class DatabaseConnectionPool {
const prepared = sql.includes('?');
let data;
if (!prepared) {
[ data ] = await this.#connectionPool.execute(sql);
} else {
[ data ] =
await this.#connectionPool.execute(sql, params);
try {
if (!prepared) {
[ data ] = await this.#connectionPool.execute(
sql
);
} else {
[ data ] = await this.#connectionPool.execute(
sql,
params
);
}
} catch (e) {
console.error(e);
data = [];
}
return data;