mirror of
https://github.com/darksaid98/oxmysql.git
synced 2026-12-02 22:22:50 +00:00
refactor: error handling
Add boolean to disable throwing error for query. Reject promises when using _async exports. Return errors as strings instead of Error (fails to serialise). Fixes #122
This commit is contained in:
1 parent
2e751a3537
commit
340ca48012
4 files changed
+49
-23
No files matched your search
@@ -10,7 +10,8 @@ export const rawExecute = async (
|
||||
invokingResource: string,
|
||||
query: string,
|
||||
parameters: CFXParameters,
|
||||
cb?: CFXCallback
|
||||
cb?: CFXCallback,
|
||||
throwError?: boolean
|
||||
) => {
|
||||
const type = executeType(query);
|
||||
parameters = parseExecute(parameters);
|
||||
@@ -45,9 +46,12 @@ export const rawExecute = async (
|
||||
|
||||
single = response.length === 1;
|
||||
} catch (err: any) {
|
||||
throw new Error(`${invokingResource} was unable to execute a query!
|
||||
${err.message}
|
||||
${err.sql}`);
|
||||
const error = `${invokingResource} was unable to execute a query!
|
||||
${err.message}
|
||||
${err.sql}`;
|
||||
|
||||
if (cb) cb(null, error)
|
||||
if (throwError) throw new Error(error)
|
||||
} finally {
|
||||
connection.release();
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user