mirror of
https://github.com/darksaid98/oxmysql.git
synced 2026-12-02 22:22:50 +00:00
fix(db): handle errors during callbacks
Handles errors that would previously disappear into the void or show as 'undefined'. In Lua this would only occur if yielding during the query callback response. Cross runtime error handling is suffering.
This commit is contained in:
1 parent
db0f29db42
commit
d80615bddc
5 files changed
+51
-34
No files matched your search
@@ -25,11 +25,11 @@ export const rawTransaction = async (
|
||||
await connection.beginTransaction();
|
||||
|
||||
for (const transaction of transactions) {
|
||||
//@ts-expect-error
|
||||
const [result, fields, executionTime] = await connection.query(transaction.query, transaction.params);
|
||||
//@ts-expect-error
|
||||
logQuery(invokingResource, transaction.query, executionTime, transaction.params);
|
||||
}
|
||||
//@ts-expect-error
|
||||
const [result, fields, executionTime] = await connection.query(transaction.query, transaction.params);
|
||||
//@ts-expect-error
|
||||
logQuery(invokingResource, transaction.query, executionTime, transaction.params);
|
||||
}
|
||||
|
||||
await connection.commit();
|
||||
|
||||
@@ -39,9 +39,7 @@ export const rawTransaction = async (
|
||||
|
||||
const transactionErrorMessage = (e as any).sql || transactionError(transactions, parameters);
|
||||
console.error(
|
||||
`${invokingResource} was unable to execute a transaction!\n${(e as Error).message}\n${
|
||||
transactionErrorMessage
|
||||
}^0`
|
||||
`${invokingResource} was unable to execute a transaction!\n${(e as Error).message}\n${transactionErrorMessage}^0`
|
||||
);
|
||||
|
||||
TriggerEvent('oxmysql:transaction-error', {
|
||||
@@ -58,5 +56,10 @@ export const rawTransaction = async (
|
||||
if (cb)
|
||||
try {
|
||||
cb(response);
|
||||
} catch {}
|
||||
} catch (err) {
|
||||
if (typeof err === 'string') {
|
||||
if (err.includes('SCRIPT ERROR:')) return console.log(err);
|
||||
console.log(`^1SCRIPT ERROR in invoking resource ${invokingResource}: ${err}^0`);
|
||||
}
|
||||
}
|
||||
};
|
||||
Reference in new issue
Block a user