From aab874e4e22471d5dc77e24aa9620df0a84f803a Mon Sep 17 00:00:00 2001 From: Kadi Kraman Date: Fri, 20 Dec 2024 15:03:52 +0000 Subject: [PATCH] Parse error only when needed --- packages/eas-cli/src/worker/upload.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/packages/eas-cli/src/worker/upload.ts b/packages/eas-cli/src/worker/upload.ts index 25e0f93312..f8f690c423 100644 --- a/packages/eas-cli/src/worker/upload.ts +++ b/packages/eas-cli/src/worker/upload.ts @@ -109,8 +109,10 @@ export async function uploadAsync(params: UploadParams): Promise { return retry(error); } - const body = await response.json().catch(() => null); - const errorMessage = body?.error ?? `Upload of "${filePath}" failed: ${response.statusText}`; + const getErrorMessage = async () => { + const body = await response.json().catch(() => null); + return body?.error ?? `Upload of "${filePath}" failed: ${response.statusText}`; + } if ( response.status === 408 || @@ -118,12 +120,12 @@ export async function uploadAsync(params: UploadParams): Promise { response.status === 429 || (response.status >= 500 && response.status <= 599) ) { - return retry(new Error(errorMessage)); + return retry(new Error(await getErrorMessage())); } else if (response.status === 413) { const message = `Upload of "${filePath}" failed: File size exceeded the upload limit`; throw new Error(message); } else if (!response.ok) { - throw new Error(errorMessage); + throw new Error(await getErrorMessage()); } return {