mirror of
https://github.com/darksaid98/oxmysql.git
synced 2026-12-02 06:28:54 +00:00
fix: error handling when using callbacks
Only allow manual error handling when using the await/sync methods, or when calling the default exports. Async/Callback returns need to throw errors for compatibility.
This commit is contained in:
1 parent
21e73c17b8
commit
bccd6a1035
3 files changed
+7
-6
No files matched your search
+3
-2
@@ -74,7 +74,7 @@ local function await(fn, query, parameters)
|
||||
end
|
||||
|
||||
p:resolve(result)
|
||||
end, GetCurrentResourceName)
|
||||
end, GetCurrentResourceName, false)
|
||||
return Await(p)
|
||||
end
|
||||
|
||||
@@ -85,7 +85,8 @@ setmetatable(MySQL, {
|
||||
self[method] = setmetatable({}, {
|
||||
|
||||
__call = function(_, query, parameters, cb)
|
||||
return oxmysql[method](nil, safeArgs(query, parameters, cb, method == 'transaction'))
|
||||
query, parameters, cb = safeArgs(query, parameters, cb, method == 'transaction')
|
||||
return oxmysql[method](nil, query, parameters, cb, GetCurrentResourceName, true)
|
||||
end,
|
||||
|
||||
__index = function(_, index)
|
||||
|
||||
@@ -77,7 +77,7 @@ export const rawExecute = async (
|
||||
.catch((err) => {
|
||||
const error = `${invokingResource} was unable to execute a query!\n${err}\n${`${query}`}`;
|
||||
|
||||
if (cb) cb(null, error);
|
||||
if (throwError) throw new Error(error);
|
||||
if (cb && !throwError) cb(null, error);
|
||||
if (throwError || !cb) throw new Error(error);
|
||||
});
|
||||
};
|
||||
@@ -30,7 +30,7 @@ export const rawQuery = async (
|
||||
}).catch((err) => {
|
||||
const error = `${invokingResource} was unable to execute a query!\n${err.message}\n${`${query} ${JSON.stringify(parameters)}`}`
|
||||
|
||||
if (cb) cb(null, error)
|
||||
if (throwError) throw new Error(error)
|
||||
if (cb && !throwError) cb(null, error);
|
||||
if (throwError || !cb) throw new Error(error);
|
||||
});
|
||||
};
|
||||
Reference in new issue
Block a user