From c18fc9cf1712615e8898f4c3ffea2cdf2f73f003 Mon Sep 17 00:00:00 2001 From: Kadi Kraman <kadi@expo.io> Date: Fri, 13 Dec 2024 17:01:50 +0000 Subject: [PATCH] Show error from request body when applicable --- packages/eas-cli/src/worker/upload.ts | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/packages/eas-cli/src/worker/upload.ts b/packages/eas-cli/src/worker/upload.ts index a139e4580e..25e0f93312 100644 --- a/packages/eas-cli/src/worker/upload.ts +++ b/packages/eas-cli/src/worker/upload.ts @@ -109,7 +109,8 @@ export async function uploadAsync(params: UploadParams): Promise<UploadResult> { return retry(error); } - const defaultErrorMessage = `Upload of "${filePath}" failed: ${response.statusText}`; + const body = await response.json().catch(() => null); + const errorMessage = body?.error ?? `Upload of "${filePath}" failed: ${response.statusText}`; if ( response.status === 408 || @@ -117,17 +118,12 @@ export async function uploadAsync(params: UploadParams): Promise<UploadResult> { response.status === 429 || (response.status >= 500 && response.status <= 599) ) { - const text = await response.text().catch(() => null); - return retry(new Error(text ? `${defaultErrorMessage}\n${text}` : defaultErrorMessage)); - } else if (response.status === 403) { - const body = await response.json(); - const message = body?.error ?? defaultErrorMessage; - throw new Error(message); + return retry(new Error(errorMessage)); } 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(defaultErrorMessage); + throw new Error(errorMessage); } return {