fix: parse raw body Buffer in Vercel webhook controller (#27384)

Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
MorganandDevin AI authored and GitHub committed 2026-01-29 11:54:32 +00:00
1 parent 2802310268
commit 447a0289d6
1 file changed
+18 -1
+18 -1
View File
@@ -27,8 +27,25 @@ export class VercelWebhookController {
@Post("deployment-promoted")
@UseGuards(VercelWebhookGuard)
@HttpCode(HttpStatus.OK)
async handlePromotion(@Body() payload: VercelWebhookPayload): Promise<{ status: string; version: string }> {
async handlePromotion(
@Body() rawBody: Buffer | VercelWebhookPayload
): Promise<{ status: string; version: string }> {
// RawBodyMiddleware provides a Buffer, need to parse it
// In test environment, body may already be parsed as object
let payload: VercelWebhookPayload;
if (Buffer.isBuffer(rawBody)) {
try {
payload = JSON.parse(rawBody.toString("utf-8")) as VercelWebhookPayload;
} catch {
this.logger.error("Failed to parse webhook payload as JSON");
return { status: "error", version: "" };
}
} else {
payload = rawBody;
}
if (payload.type !== "deployment.promoted") {
this.logger.log(`Ignoring webhook event type: ${payload.type}`);
return { status: "ignored", version: "" };
}