Skip to content

Commit

Permalink
fix: Start returning proper error message when raising RequestError i…
Browse files Browse the repository at this point in the history
…n poll_upload_response, to hit to users what is going on. Fixes #141
  • Loading branch information
vipulnsward committed Feb 25, 2024
1 parent 0eda04b commit 0117e1a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/uploadcare/client/uploader_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,10 @@ def poll_upload_response(token)
base_sleep_seconds: Uploadcare.config.base_request_sleep,
max_sleep_seconds: Uploadcare.config.max_request_sleep) do
response = get_upload_from_url_status(token)
raise RequestError if %w[progress waiting unknown].include?(response.success[:status])

if %w[progress waiting unknown].include?(response.success[:status])
raise RequestError, 'Upload is taking longer than expected. Try increasing the max_request_tries config if you know your file uploads will take more time.' # rubocop:disable Layout/LineLength
end

response
end
Expand Down
9 changes: 9 additions & 0 deletions spec/uploadcare/entity/uploader_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,15 @@ module Entity
expect(upload[0]).to be_kind_of(Uploadcare::Entity::File)
end
end

it 'raises error with information if file upload takes time' do
Uploadcare.config.max_request_tries = 1
VCR.use_cassette('upload_upload_from_url') do
url = 'https://placekitten.com/2250/2250'
error_str = 'Upload is taking longer than expected. Try increasing the max_request_tries config if you know your file uploads will take more time.' # rubocop:disable Layout/LineLength
expect { subject.upload(url) }.to raise_error(RequestError, error_str)
end
end
end

describe 'multipart_upload' do
Expand Down

0 comments on commit 0117e1a

Please sign in to comment.