-
Notifications
You must be signed in to change notification settings - Fork 1
fix: improve file upload resilience #1476
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -316,24 +316,33 @@ async function checkExpectedMTime(path: string, expectedMTimeUnix: bigint) { | |||||||||||||
| } | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| function isExpiredTokenError(body: string): boolean { | ||||||||||||||
| return body.includes("<Code>ExpiredToken</Code>"); | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| function checkStatusCodeOk( | ||||||||||||||
| statusCode: number, | ||||||||||||||
| body: string, | ||||||||||||||
| headers: IncomingHttpHeaders, | ||||||||||||||
| info: UploadAPI_GetPartURL_Response, | ||||||||||||||
| ) { | ||||||||||||||
| const message = | ||||||||||||||
| `response is not ok, status code: ${statusCode},` + | ||||||||||||||
| ` body: ${body}, headers: ${JSON.stringify(headers)}, url: ${info.uploadUrl}`; | ||||||||||||||
|
Comment on lines
+329
to
+331
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The error message includes the full
Suggested change
|
||||||||||||||
|
|
||||||||||||||
| if (statusCode == 400) { | ||||||||||||||
| throw new BadRequestError( | ||||||||||||||
| `response is not ok, status code: ${statusCode},` + | ||||||||||||||
| ` body: ${body}, headers: ${JSON.stringify(headers)}, url: ${info.uploadUrl}`, | ||||||||||||||
| ); | ||||||||||||||
| // S3 may return 400 with ExpiredToken when the STS session credentials | ||||||||||||||
| // used to sign the pre-signed URL have expired. This is recoverable: | ||||||||||||||
| // a retry will request a fresh pre-signed URL from the backend. | ||||||||||||||
| if (isExpiredTokenError(body)) { | ||||||||||||||
| throw new NetworkError(message); | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| throw new BadRequestError(message); | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| if (statusCode != 200) { | ||||||||||||||
| throw new NetworkError( | ||||||||||||||
| `response is not ok, status code: ${statusCode},` + | ||||||||||||||
| ` body: ${body}, headers: ${JSON.stringify(headers)}, url: ${info.uploadUrl}`, | ||||||||||||||
| ); | ||||||||||||||
| throw new NetworkError(message); | ||||||||||||||
| } | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
|
|
||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using
String.prototype.includes()for this check is a bit fragile because it performs a simple substring search. A regular expression is more robust as it can match the specific XML tag structure, making the check less prone to accidental matches and more resilient to potential (though unlikely) whitespace variations in the S3 error response.