Skip to content

Commit

Permalink
Parse error only when needed
Browse files Browse the repository at this point in the history
  • Loading branch information
kadikraman committed Dec 20, 2024
1 parent 2a96d04 commit aab874e
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions packages/eas-cli/src/worker/upload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,21 +109,23 @@ export async function uploadAsync(params: UploadParams): Promise<UploadResult> {
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 ||
response.status === 409 ||
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 {
Expand Down

0 comments on commit aab874e

Please sign in to comment.