Skip to content

Your always-on AI coworkers that move between text, calls, and Slack.

TypeScript

fix: return not found for unknown page conversations (#14)

Charan Rathore96516896b933
diff --git a/src/server/page-routes.ts b/src/server/page-routes.ts
index 4b4bb14..689a609 100644
--- a/src/server/page-routes.ts
+++ b/src/server/page-routes.ts
@@ -131,13 +131,16 @@ export function pageRoutes(platform: Platform) {
? c.json({ error: 'Invalid JSON request.' }, 400)
: error instanceof PageError
? c.json({ error: error.message }, error.status)
- : c.json(
- {
- error:
- 'Page operation could not complete. Check Intelligence setup or retry; your draft has not been discarded.',
- },
- 503,
- ),
+ : error.message ===
+ 'Conversation does not belong to this Dot and owner.'
+ ? c.json({ error: error.message }, 404)
+ : c.json(
+ {
+ error:
+ 'Page operation could not complete. Check Intelligence setup or retry; your draft has not been discarded.',
+ },
+ 503,
+ ),
);
return app;
}
diff --git a/tests/page-routes.test.ts b/tests/page-routes.test.ts
index a14d023..19f3fb8 100644
--- a/tests/page-routes.test.ts
+++ b/tests/page-routes.test.ts
@@ -1,4 +1,4 @@
-import { afterEach, expect, it } from 'vitest';
+import { afterEach, expect, it, vi } from 'vitest';
import { Store } from '../src/server/store.js';
import { WorkspaceStore } from '../src/server/workspace.js';
import { Platform } from '../src/server/platform.js';
@@ -22,6 +22,7 @@ function fixture(ownerToken?: string) {
});
return {
ws,
+ platform,
app: createApp({
store,
runner: new Runner(store, config),
@@ -268,3 +269,48 @@ it('restores review receipts through the owner API with current thread and Space
ws.updateDot(dot.id, { ...dot, spaceId: other.id, spaceIds: [other.id] });
expect((await app.request(`${base}/call`, { headers })).status).toBe(403);
});
+it.each([
+ ['GET', '/reviewed-page/tool'],
+ ['POST', '/reviewed-page'],
+ ['GET', '/page-context'],
+ ['POST', '/page'],
+])(
+ 'returns 404 for an unknown conversation on %s %s',
+ async (method, suffix) => {
+ const { ws, app } = fixture();
+ const body =
+ suffix === '/reviewed-page'
+ ? {
+ title: 'Draft',
+ content: 'Text',
+ spaceId: ws.spaces()[0].id,
+ toolCallId: 'tool',
+ }
+ : { title: 'Draft' };
+ const response = await app.request(
+ `/api/conversations/missing${suffix}`,
+ method === 'GET' ? undefined : request(body),
+ );
+ expect(response.status).toBe(404);
+ expect(await response.json()).toEqual({
+ error: 'Conversation does not belong to this Dot and owner.',
+ });
+ },
+);
+
+it('keeps real Intelligence failures as 503 without exposing details', async () => {
+ const { ws, app, platform } = fixture();
+ ws.bindThread('valid-thread', ws.dots()[0].id, 'Conversation');
+ vi.spyOn(platform.pages, 'saveConversation').mockRejectedValueOnce(
+ new Error('Provider secret'),
+ );
+ const response = await app.request(
+ '/api/conversations/valid-thread/page',
+ request({ title: 'Draft' }),
+ );
+ expect(response.status).toBe(503);
+ expect(await response.json()).toEqual({
+ error:
+ 'Page operation could not complete. Check Intelligence setup or retry; your draft has not been discarded.',
+ });
+});