fix(mindspace): map publication RPC errors to HTTP status codes

Return 404/401/403 from MindSpace RPC for known publication errors and
preserve error codes through the Portal remote adapter.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
john
2026-07-05 19:44:58 +08:00
parent 85061dfa9f
commit 53eb0014ba
4 changed files with 130 additions and 12 deletions
@@ -196,3 +196,52 @@ test('rpc invocation revives JSON-serialized buffers before dispatch', async ()
assert.deepEqual(response.body, { isBuffer: true, size: payload.length });
assert.equal(Buffer.isBuffer(adapter.calls.writeUploadContent[0][2]), true);
});
test('rpc maps publication_not_found to 404 with error code', async () => {
const adapter = createStubAdapter();
adapter.publicationService.resolvePublic = async () => {
const error = new Error('公开页面不存在');
error.code = 'publication_not_found';
throw error;
};
const handler = await createMindSpaceRpcRequestHandler({
adapter,
env: {
MINDSPACE_MEMIND_ROOT: '..',
},
});
const response = await runRequest(handler, {
method: 'POST',
path: '/mindspace/v1/adapter/publicationService/resolvePublic',
body: JSON.stringify({ args: ['john', 'missing-page', null, null, {}] }),
});
assert.equal(response.statusCode, 404);
assert.equal(response.body.code, 'publication_not_found');
assert.match(response.body.message, /公开页面不存在/);
});
test('rpc maps publication_login_required to 401 with error code', async () => {
const adapter = createStubAdapter();
adapter.publicationService.resolvePublic = async () => {
const error = new Error('登录后才能访问此页面');
error.code = 'publication_login_required';
throw error;
};
const handler = await createMindSpaceRpcRequestHandler({
adapter,
env: {
MINDSPACE_MEMIND_ROOT: '..',
},
});
const response = await runRequest(handler, {
method: 'POST',
path: '/mindspace/v1/adapter/publicationService/resolvePublic',
body: JSON.stringify({ args: ['john', 'login-page', null, null, {}] }),
});
assert.equal(response.statusCode, 401);
assert.equal(response.body.code, 'publication_login_required');
});