-
Notifications
You must be signed in to change notification settings - Fork 0
chore: Error handling when upload id I'd incorrect for Resumable upload #6
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 2 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 |
|---|---|---|
|
|
@@ -149,7 +149,9 @@ def initiate_resumable_upload(client) | |
| # Reinitiating resumable upload | ||
| def reinitiate_resumable_upload(client) | ||
| logger.debug { sprintf('Restarting resumable upload command to %s', url) } | ||
| check_resumable_upload client | ||
| unless check_resumable_upload client | ||
| return false | ||
| end | ||
| upload_io.pos = @offset | ||
| end | ||
|
|
||
|
|
@@ -224,6 +226,10 @@ def check_resumable_upload(client) | |
| # Initiating call | ||
| response = client.put(@upload_url, "", request_header) | ||
| handle_resumable_upload_http_response_codes(response) | ||
| if response.status.to_i == 404 | ||
| logger.debug { sprintf("Failed to fetch upload session. Response: #{response.status.to_i} - #{response.body}") } | ||
| false | ||
| end | ||
|
Comment on lines
226
to
+230
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. This change introduces a bug that breaks the resumable upload functionality. When the server responds with a 308 status (Resume Incomplete), As a result, in To fix this, result = handle_resumable_upload_http_response_codes(response)
if response.status.to_i == 404
logger.debug { sprintf("Failed to fetch upload session. Response: #{response.status.to_i} - #{response.body}") }
return false
end
result
Collaborator
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. can you check this does handle_resumable_upload_http_response_codes is returning 404 specifically? @shubhangi-google
Owner
Author
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. no handle_resumable_upload_http_response_codes will not return 404 it sets the value of variable which tells if the ubload is complete or incomplete
Collaborator
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. ok got it, the response object is filled in that method, and check 404 here, other than 404 it return true?
Owner
Author
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. yes either it will return true or it will do further processing depending on the flow |
||
| end | ||
|
|
||
| # Cancel resumable upload | ||
|
|
@@ -234,14 +240,13 @@ def cancel_resumable_upload(client) | |
| # Initiating call | ||
| response = client.delete(@upload_url, nil, request_header) | ||
| handle_resumable_upload_http_response_codes(response) | ||
|
|
||
| if !@upload_incomplete && (400..499).include?(response.status.to_i) | ||
| if !@upload_incomplete && (400..499).include?(response.status.to_i) && response.status.to_i != 404 | ||
|
Collaborator
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. it seems 404 check should be with or condition?
Owner
Author
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. yes it comes in this condition but we want to perform additional actions in case of 404
Collaborator
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. ok for 404 else case will work?
Owner
Author
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. yes |
||
| @close_io_on_finish = true | ||
| true # method returns true if upload is successfully cancelled | ||
| else | ||
| logger.debug { sprintf("Failed to cancel upload session. Response: #{response.status.to_i} - #{response.body}") } | ||
| false | ||
| end | ||
|
|
||
| end | ||
|
|
||
| def handle_resumable_upload_http_response_codes(response) | ||
|
|
||
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.
For improved conciseness and readability, you can use a one-line guard clause here.