Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions app/api/v1/ai/usage/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,8 @@ export async function GET(request: Request) {
} catch (err) {
return Response.json(
{
error: {
message:
err instanceof Error ? err.message : 'Failed to get AI usage',
},
error:
err instanceof Error ? err.message : 'Failed to get AI usage',
},
{ status: 500 },
);
Comment on lines 38 to 45
Expand Down
8 changes: 2 additions & 6 deletions app/api/v1/analytics/trends/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export async function GET(request: Request) {

if (!from || !to) {
return Response.json(
{ error: { message: 'from and to query parameters are required' } },
{ error: 'from and to query parameters are required' },
{ status: 400 },
);
Comment on lines 25 to 29
}
Expand Down Expand Up @@ -55,11 +55,7 @@ export async function GET(request: Request) {
return jsonWithContext(auth.context, { data: snapshots });
} catch (err) {
return Response.json(
{
error: {
message: err instanceof Error ? err.message : 'Failed to get trends',
},
},
{ error: err instanceof Error ? err.message : 'Failed to get trends' },
{ status: 500 },
);
Comment on lines 56 to 60
}
Expand Down
10 changes: 3 additions & 7 deletions app/api/v1/forms/[formId]/analytics/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@ export async function GET(
return jsonWithContext(
auth.context,
{
error: {
message: 'Form analytics requires a Growth or Enterprise entitlement',
},
error: 'Form analytics requires a Growth or Enterprise entitlement',
},
{ status: 403 },
);
Expand All @@ -46,10 +44,8 @@ export async function GET(
} catch (err) {
return Response.json(
{
error: {
message:
err instanceof Error ? err.message : 'Failed to get analytics',
},
error:
err instanceof Error ? err.message : 'Failed to get analytics',
},
{ status: 500 },
);
Comment on lines 44 to 51
Expand Down
6 changes: 2 additions & 4 deletions app/api/v1/forms/[formId]/duplicate/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,8 @@ export async function POST(
} catch (err) {
return Response.json(
{
error: {
message:
err instanceof Error ? err.message : 'Failed to duplicate form',
},
error:
err instanceof Error ? err.message : 'Failed to duplicate form',
},
{ status: 500 },
);
Comment on lines 31 to 38
Expand Down
6 changes: 2 additions & 4 deletions app/api/v1/forms/[formId]/publish/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,8 @@ export async function POST(
} catch (err) {
return Response.json(
{
error: {
message:
err instanceof Error ? err.message : 'Failed to publish form',
},
error:
err instanceof Error ? err.message : 'Failed to publish form',
},
{ status: 500 },
);
Comment on lines 26 to 33
Expand Down
10 changes: 3 additions & 7 deletions app/api/v1/forms/[formId]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export async function GET(
return jsonWithContext(auth.context, { data: form });
} catch {
return Response.json(
{ error: { message: 'Form not found' } },
{ error: 'Form not found' },
{ status: 404 },
);
Comment on lines 28 to 32
}
Expand Down Expand Up @@ -65,11 +65,7 @@ export async function PATCH(
return jsonWithContext(auth.context, { data: form });
} catch (err) {
return Response.json(
{
error: {
message: err instanceof Error ? err.message : 'Failed to update form',
},
},
{ error: err instanceof Error ? err.message : 'Failed to update form' },
{ status: 500 },
);
}
Expand All @@ -93,7 +89,7 @@ export async function DELETE(
return jsonWithContext(auth.context, { data: form });
} catch {
return Response.json(
{ error: { message: 'Form not found' } },
{ error: 'Form not found' },
{ status: 404 },
);
Comment on lines 90 to 94
}
Expand Down
14 changes: 3 additions & 11 deletions app/api/v1/forms/[formId]/submissions/[submissionId]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,7 @@ export async function GET(
return jsonWithContext(auth.context, { data: submission });
} catch (err) {
return Response.json(
{
error: {
message: err instanceof Error ? err.message : 'Submission not found',
},
},
{ error: err instanceof Error ? err.message : 'Submission not found' },
{ status: 404 },
);
Comment on lines 28 to 32
}
Expand All @@ -53,7 +49,7 @@ export async function PATCH(

if (!body.status || !['approved', 'rejected'].includes(body.status)) {
return Response.json(
{ error: { message: 'status must be "approved" or "rejected"' } },
{ error: 'status must be "approved" or "rejected"' },
{ status: 400 },
);
}
Comment on lines 50 to 55
Expand All @@ -70,11 +66,7 @@ export async function PATCH(
return jsonWithContext(auth.context, { data: submission });
} catch (err) {
return Response.json(
{
error: {
message: err instanceof Error ? err.message : 'Review failed',
},
},
{ error: err instanceof Error ? err.message : 'Review failed' },
{ status: 500 },
);
}
Expand Down
8 changes: 4 additions & 4 deletions app/api/v1/forms/[formId]/submissions/export/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export async function GET(
if (!isUuid(formId)) {
return jsonWithContext(
auth.context,
{ error: { message: 'Invalid formId' } },
{ error: 'Invalid formId' },
{ status: 400 },
);
}
Expand All @@ -73,15 +73,15 @@ export async function GET(
if (formError) {
return jsonWithContext(
auth.context,
{ error: { message: 'Failed to load form for export' } },
{ error: 'Failed to load form for export' },
{ status: 500 },
);
}

if (!form) {
return jsonWithContext(
auth.context,
{ error: { message: 'Form not found' } },
{ error: 'Form not found' },
{ status: 404 },
);
}
Expand All @@ -102,7 +102,7 @@ export async function GET(
if (submissionsError) {
return jsonWithContext(
auth.context,
{ error: { message: 'Failed to load form submissions for export' } },
{ error: 'Failed to load form submissions for export' },
{ status: 500 },
);
}
Expand Down
18 changes: 5 additions & 13 deletions app/api/v1/forms/[formId]/submissions/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,8 @@ export async function GET(
} catch (err) {
return Response.json(
{
error: {
message:
err instanceof Error ? err.message : 'Failed to list submissions',
},
error:
err instanceof Error ? err.message : 'Failed to list submissions',
},
{ status: 500 },
);
Comment on lines 48 to 55
Expand Down Expand Up @@ -90,20 +88,14 @@ export async function POST(
if (err instanceof FormValidationError) {
return Response.json(
{
error: {
message: 'Validation failed',
details: err.validationErrors,
},
error: 'Validation failed',
details: err.validationErrors,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Wrap validation details to match Error schema

When a form submission fails validation, this newly promoted top-level details value is err.validationErrors, which is an array of field errors. The OpenAPI Error component this change is trying to satisfy declares details as an object (openapi.json:2096-2098), so generated clients or response validators still see a schema mismatch for 422 responses; wrap the array in an object such as details: { validationErrors: ... } or update the schema accordingly.

Useful? React with 👍 / 👎.

},
{ status: 422 },
);
Comment on lines 88 to 95
}
return Response.json(
{
error: {
message: err instanceof Error ? err.message : 'Submission failed',
},
},
{ error: err instanceof Error ? err.message : 'Submission failed' },
{ status: 500 },
);
}
Expand Down
14 changes: 3 additions & 11 deletions app/api/v1/forms/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,7 @@ export async function GET(request: Request) {
);
} catch (err) {
return Response.json(
{
error: {
message: err instanceof Error ? err.message : 'Failed to list forms',
},
},
{ error: err instanceof Error ? err.message : 'Failed to list forms' },
{ status: 500 },
);
}
Expand All @@ -60,7 +56,7 @@ export async function POST(request: Request) {

if (!title || typeof title !== 'string') {
return Response.json(
{ error: { message: 'title is required' } },
{ error: 'title is required' },
{ status: 400 },
);
}
Comment on lines 57 to 62
Expand Down Expand Up @@ -90,11 +86,7 @@ export async function POST(request: Request) {
return Response.json({ data: form }, { status: 201 });
} catch (err) {
return Response.json(
{
error: {
message: err instanceof Error ? err.message : 'Failed to create form',
},
},
{ error: err instanceof Error ? err.message : 'Failed to create form' },
{ status: 500 },
);
Comment on lines 86 to 91
}
Expand Down
4 changes: 1 addition & 3 deletions app/api/v1/reports/custom/_entitlement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ export async function requireCustomReportsEntitlement(
return jsonWithContext(
context,
{
error: {
message: 'Custom reports require a Growth or Enterprise entitlement',
},
error: 'Custom reports require a Growth or Enterprise entitlement',
},
{ status: 403 },
);
Expand Down
14 changes: 5 additions & 9 deletions app/api/v1/reports/custom/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,8 @@ export async function GET(request: Request) {
} catch (err) {
return Response.json(
{
error: {
message:
err instanceof Error ? err.message : 'Failed to list reports',
},
error:
err instanceof Error ? err.message : 'Failed to list reports',
},
{ status: 500 },
);
Comment on lines 35 to 42
Expand All @@ -60,7 +58,7 @@ export async function POST(request: Request) {

if (!name || typeof name !== 'string') {
return Response.json(
{ error: { message: 'name is required' } },
{ error: 'name is required' },
{ status: 400 },
);
}
Comment on lines 59 to 64
Expand All @@ -83,10 +81,8 @@ export async function POST(request: Request) {
} catch (err) {
return Response.json(
{
error: {
message:
err instanceof Error ? err.message : 'Failed to create report',
},
error:
err instanceof Error ? err.message : 'Failed to create report',
},
{ status: 500 },
);
Comment on lines 81 to 88
Expand Down
Loading