Skip to content

Commit f749f97

Browse files
committed
fix: guard request.json() with try-catch to match newer admin route pattern
1 parent 0f901b8 commit f749f97

2 files changed

Lines changed: 14 additions & 2 deletions

File tree

apps/webapp/app/routes/admin.api.orgs.$orgId.feature-flags.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,13 @@ export async function action({ request, params }: ActionFunctionArgs) {
6565
}
6666

6767
const { orgId } = ParamsSchema.parse(params);
68-
const body = await request.json();
68+
69+
let body: unknown;
70+
try {
71+
body = await request.json();
72+
} catch {
73+
return json({ error: "Invalid JSON body" }, { status: 400 });
74+
}
6975

7076
let featureFlags: typeof Prisma.JsonNull | Record<string, unknown>;
7177

apps/webapp/app/routes/admin.feature-flags.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,13 @@ export const action = async ({ request }: ActionFunctionArgs) => {
5858
throw new Response("Unauthorized", { status: 403 });
5959
}
6060

61-
const body = await request.json();
61+
let body: unknown;
62+
try {
63+
body = await request.json();
64+
} catch {
65+
return json({ error: "Invalid JSON body" }, { status: 400 });
66+
}
67+
6268
const payloadSchema = z.object({ flags: z.record(z.unknown()) });
6369
const parsed = payloadSchema.safeParse(body);
6470
if (!parsed.success) {

0 commit comments

Comments
 (0)