From 58b4853baf5b1b6d340310eb842ec4547716825f Mon Sep 17 00:00:00 2001 From: Pooya Parsa Date: Wed, 23 Aug 2023 05:27:31 +0200 Subject: [PATCH] refactor: simplify `normalizeLambdaOutgoingBody` --- src/runtime/utils.lambda.ts | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/src/runtime/utils.lambda.ts b/src/runtime/utils.lambda.ts index 40a8f1392b..faafae5b01 100644 --- a/src/runtime/utils.lambda.ts +++ b/src/runtime/utils.lambda.ts @@ -38,15 +38,11 @@ export async function normalizeLambdaOutgoingBody( if (!body) { return ""; } - body = await _toBuffer(body as any); - if (Buffer.isBuffer(body)) { - const contentType = (headers["content-type"] as string) || ""; - if (isTextType(contentType)) { - return body.toString("utf8"); - } - return body.toString("base64"); - } - throw new Error(`Unsupported body type: ${typeof body}`); + const buffer = await _toBuffer(body as any); + const contentType = (headers["content-type"] as string) || ""; + return isTextType(contentType) + ? buffer.toString("utf8") + : buffer.toString("base64"); } function _toBuffer(data: ReadableStream | Readable | Uint8Array) {