refactor(onebot): unify action-error retcode at the runAction seam
将「动作抛错返回什么错误码」从各处不一致(100 / 1200 / 漏包→1200)收敛到唯一 兜底处 ApiHandler.runAction,统一为 ACTION_FAILED(100) + error.message。 阶段 1(改 seam 本身): - runAction catch:默认码 1200 → 100;文案 'internal error' 兜底改为 String(error)。 OidbError.message 本就含 QQ 服务端 code,无需特判。 - 新增 3 个测试锁定策略:抛 Error→100+message;抛 OidbError→100 且 wording 含 code+server msg;抛非 Error→100+String()。 - rename_group_file 那个原断言 1200 的测试(未包裹动作、落 runAction)改为 100。 各 action 里多余的 try/catch(qzone/group-album 等仍返回 1200)留待后续阶段删除, 在此之前其失败不经此 seam。onebot 全量 516 全绿、typecheck 干净。
This commit is contained in:
3 files changed
+45
-7
No files matched your search
@@ -178,15 +178,23 @@ export class ApiHandler {
|
||||
response = await handler(params, sink);
|
||||
this.log.trace(() => [`${action} ⇒ ${response.status} (${Date.now() - startedAt}ms)`]);
|
||||
} catch (error) {
|
||||
// Action failures are almost always param-shape problems coming
|
||||
// from the OneBot client; warn (not error) is the right level so
|
||||
// the log file stays a useful signal of real internal faults.
|
||||
// Single error seam: any throw from a handler (bridge/OIDB business
|
||||
// failure or an unexpected internal fault) maps here to one policy —
|
||||
// ACTION_FAILED (100) + the error's message. Action `run` bodies
|
||||
// shouldn't need to hand-roll their own try/catch → failedResponse:
|
||||
// doing so only produced inconsistent retcodes (100 vs 1200) for the same
|
||||
// kind of failure. The remaining per-action catches (qzone / group-album,
|
||||
// still returning 1200) are being removed in a follow-up phase — until
|
||||
// then their failures never reach this seam. `OidbError.message` already
|
||||
// carries the QQ server code, so no special-casing is needed. warn (not
|
||||
// error) keeps the log file a useful signal without drowning it in
|
||||
// expected client-side failures.
|
||||
this.log.warn('%s failed: %s\n%s',
|
||||
action,
|
||||
error instanceof Error ? error.message : String(error),
|
||||
error instanceof Error ? (error.stack ?? '') : '');
|
||||
const message = error instanceof Error ? error.message : 'internal error';
|
||||
response = failedResponse(RETCODE.INTERNAL_ERROR, message);
|
||||
const message = error instanceof Error ? error.message : String(error);
|
||||
response = failedResponse(RETCODE.ACTION_FAILED, message);
|
||||
}
|
||||
this.notifyObservers(action, params, response, Date.now() - startedAt);
|
||||
return response;
|
||||
|
||||
Reference in new issue
Block a user