From 7eabc9fb1b38c3632d86e592de31769d323c1d8b Mon Sep 17 00:00:00 2001 From: Anar Kafkas <36949216+kafkas@users.noreply.github.com> Date: Thu, 19 Oct 2023 17:19:49 +0300 Subject: [PATCH] Don't expect rawBody as json string (#222) --- .../fe-bundle/src/pages/api/revalidate-v2.ts | 22 ++++++------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/packages/ui/fe-bundle/src/pages/api/revalidate-v2.ts b/packages/ui/fe-bundle/src/pages/api/revalidate-v2.ts index 2ee2226a8c..c7021849f9 100644 --- a/packages/ui/fe-bundle/src/pages/api/revalidate-v2.ts +++ b/packages/ui/fe-bundle/src/pages/api/revalidate-v2.ts @@ -31,22 +31,14 @@ interface ErrorParseResult { } function parseRequestBody(rawBody: unknown): ParseResult { - try { - if (typeof rawBody !== "string") { - return { success: false, message: "Request body missing." }; - } - const parsed = JSON.parse(rawBody); - if (!isPlainObject(parsed)) { - return { success: false, message: "Request body is not a plain object." }; - } - const { path } = parsed; - if (typeof path !== "string") { - return { success: false, message: 'Expected "path" in request body to be a string.' }; - } - return { success: true, request: { path } }; - } catch (e) { - return { success: false, message: "Cannot parse request body as JSON." }; + if (!isPlainObject(rawBody)) { + return { success: false, message: "Request body is not a plain object." }; + } + const { path } = rawBody; + if (typeof path !== "string") { + return { success: false, message: 'Expected "path" in request body to be a string.' }; } + return { success: true, request: { path } }; } const handler: NextApiHandler = async (req, res: NextApiResponse) => {