From 5b78e0586fd351258ccc05c8ba89a2ba66681b0d Mon Sep 17 00:00:00 2001 From: Stainless Bot <107565488+stainless-bot@users.noreply.github.com> Date: Mon, 17 Jul 2023 19:43:30 -0500 Subject: [PATCH] fix: fix error in environments without `TextEncoder` (#70) --- src/core.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/core.ts b/src/core.ts index d5d0c043..24227f5b 100644 --- a/src/core.ts +++ b/src/core.ts @@ -128,9 +128,11 @@ export abstract class APIClient { return Buffer.byteLength(body, 'utf8').toString(); } - const encoder = new TextEncoder(); - const encoded = encoder.encode(body); - return encoded.length.toString(); + if (typeof TextEncoder !== 'undefined') { + const encoder = new TextEncoder(); + const encoded = encoder.encode(body); + return encoded.length.toString(); + } } return null;