Skip to content

Commit

Permalink
Show error from request body when applicable
Browse files Browse the repository at this point in the history
  • Loading branch information
kadikraman committed Dec 13, 2024
1 parent a13d0b3 commit c18fc9c
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions packages/eas-cli/src/worker/upload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,25 +109,21 @@ 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 ||
response.status === 409 ||
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 {
Expand Down

0 comments on commit c18fc9c

Please sign in to comment.