Skip to content

⭐️⭐️⭐️ Open-source, self-hosted alternative to Linear and Plane. Project management and issue tracking where teams and AI agents work side by side to plan and ship products.

fix(api): keep the failed statement out of error responses (#311)

Croff721cb18dddbd
diff --git a/apps/api/src/modules/projects/__tests__/integration/projects.test.ts b/apps/api/src/modules/projects/__tests__/integration/projects.test.ts
index 508b1146..19521347 100644
--- a/apps/api/src/modules/projects/__tests__/integration/projects.test.ts
+++ b/apps/api/src/modules/projects/__tests__/integration/projects.test.ts
@@ -551,7 +551,7 @@ describe('projects', () => {
expect(copied.data?.[0]).toMatchObject({ runnerScope: 'owner', ownerUserId: user.userId });
});
- it('returns 400 with an error body on a duplicate key', async () => {
+ it('rejects a duplicate key with 409 and no statement in the body', async () => {
const { api } = await signUpClient();
await api.projects.post({ key: 'SRC', name: 'Source' });
await api.projects.post({ key: 'DST', name: 'Existing' });
@@ -560,7 +560,8 @@ describe('projects', () => {
key: 'DST',
name: 'Destination',
});
- expect(res.status).toBe(400);
+ expect(res.status).toBe(409);
+ expect(JSON.stringify(res.error?.value)).not.toContain('Failed query');
});
it('returns 404 for an unknown source project', async () => {
diff --git a/apps/api/src/modules/projects/index.ts b/apps/api/src/modules/projects/index.ts
index 53e2257e..ffcbe19c 100644
--- a/apps/api/src/modules/projects/index.ts
+++ b/apps/api/src/modules/projects/index.ts
@@ -113,20 +113,13 @@ export const projectRoutes = new Elysia({ name: 'projects', detail: { tags: ['Pr
) {
await assertProjectOwner(project.id, current);
}
- try {
- set.status = 201;
- return await copyProject(project.id, meta, current.id, include);
- } catch (err) {
- // Return the real cause in the body so the UI shows the actual error.
- console.error('copyProject failed:', err);
- set.status = 400;
- return { error: err instanceof Error ? err.message : 'Failed to copy project' };
- }
+ set.status = 201;
+ return await copyProject(project.id, meta, current.id, include);
},
{
body: copyProjectBody,
permission: ['work_items', 'read'],
- response: { 201: ProjectResponse, ...commonErrors },
+ response: { 201: ProjectResponse, ...commonErrors, ...errors(409) },
detail: {
summary: 'Copy a project',
description:
diff --git a/apps/api/src/planner.ts b/apps/api/src/planner.ts
index 5fa0784f..7b220d59 100644
--- a/apps/api/src/planner.ts
+++ b/apps/api/src/planner.ts
@@ -76,9 +76,11 @@ export const planner = new Elysia({ name: 'planner' })
set.status = 409;
return { error: 'A record with this name already exists.' };
}
+ // The message stays in the log only. drizzle puts the failed statement and its
+ // parameters in it, and the public routes would hand that to anyone.
console.error('[planner] unhandled error:', error);
set.status = 500;
- return { error: error instanceof Error ? error.message : 'Internal server error' };
+ return { error: 'Internal server error' };
})
.use(projectRoutes)
.use(memberRoutes)