fix: throw hook error

This commit is contained in:
Gabe
2025-11-20 22:27:27 +08:00
parent 86a312ea6b
commit 9d9bbd3821

View File

@@ -739,6 +739,13 @@ export const genTransReq = async ({ reqHook, ...args }) => {
// 执行 request hook // 执行 request hook
if (reqHook?.trim() && !events) { if (reqHook?.trim() && !events) {
try { try {
const req = {
url,
body,
headers,
userMsg,
method,
};
interpreter.run(`exports.reqHook = ${reqHook}`); interpreter.run(`exports.reqHook = ${reqHook}`);
const hookResult = await interpreter.exports.reqHook( const hookResult = await interpreter.exports.reqHook(
{ {
@@ -747,20 +754,16 @@ export const genTransReq = async ({ reqHook, ...args }) => {
defaultSubtitlePrompt, defaultSubtitlePrompt,
defaultNobatchPrompt, defaultNobatchPrompt,
defaultNobatchUserPrompt, defaultNobatchUserPrompt,
req,
}, },
{ req
url,
body,
headers,
userMsg,
method,
}
); );
if (hookResult && hookResult.url) { if (hookResult && hookResult.url) {
return genInit(hookResult); return genInit(hookResult);
} }
} catch (err) { } catch (err) {
kissLog("run req hook", err); kissLog("run req hook", err);
throw new Error(`Request hook error: ${err.message}`);
} }
} }
@@ -817,6 +820,7 @@ export const parseTransRes = async (
} }
} catch (err) { } catch (err) {
kissLog("run res hook", err); kissLog("run res hook", err);
throw new Error(`Response hook error: ${err.message}`);
} }
} }