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
@@ -730,13 +730,13 @@ describe('extended-actions / rename_group_file', () => {
|
||||
expect(rename).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('surfaces oidb errors (handler maps a thrown error to INTERNAL_ERROR, as its sibling file ops do)', async () => {
|
||||
it('surfaces oidb errors — a thrown error maps to the single seam (ACTION_FAILED 100 + message)', async () => {
|
||||
const rename = vi.fn(async () => { throw new Error('rename rejected'); });
|
||||
const bridge = fakeBridge({ apis: { groupFile: { rename } } });
|
||||
const res = await makeHandler(fakeCtx(bridge)).handle('rename_group_file', {
|
||||
group_id: 1, file_id: '/a', current_parent_directory: '/', new_name: 'x',
|
||||
});
|
||||
expect(res).toMatchObject({ status: 'failed', retcode: 1200, wording: 'rename rejected' });
|
||||
expect(res).toMatchObject({ status: 'failed', retcode: 100, wording: 'rename rejected' });
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in new issue
Block a user