Skip to content

Commit

Permalink
Don't expect rawBody as json string (#222)
Browse files Browse the repository at this point in the history
  • Loading branch information
kafkas authored Oct 19, 2023
1 parent 98846b4 commit 7eabc9f
Showing 1 changed file with 7 additions and 15 deletions.
22 changes: 7 additions & 15 deletions packages/ui/fe-bundle/src/pages/api/revalidate-v2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<ResponseBody>) => {
Expand Down

1 comment on commit 7eabc9f

@vercel
Copy link

@vercel vercel bot commented on 7eabc9f Oct 19, 2023

Choose a reason for hiding this comment

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

Successfully deployed to the following URLs:

fern-dev – ./packages/ui/fe-bundle

fern-dev-git-main-buildwithfern.vercel.app
fern-dev-buildwithfern.vercel.app
devtest.buildwithfern.com
app-dev.buildwithfern.com

Please sign in to comment.