From 4c2d77c5140aee299a6fc7d282555ea511d29a75 Mon Sep 17 00:00:00 2001 From: artemlutsenko Date: Thu, 29 Jun 2023 11:40:09 +0300 Subject: [PATCH] fix error on response with code 429 --- lib/dropbox_api/endpoints/base.rb | 17 +++++++++++++---- .../upload/too_many_write_operations.yml | 5 ++--- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/lib/dropbox_api/endpoints/base.rb b/lib/dropbox_api/endpoints/base.rb index 2ccc4268..b8bc768e 100644 --- a/lib/dropbox_api/endpoints/base.rb +++ b/lib/dropbox_api/endpoints/base.rb @@ -43,10 +43,19 @@ def process_response(raw_response) raw_response.env[:api_result]['error'] ) when 429 - error = DropboxApi::Errors::TooManyRequestsError.build( - raw_response.env[:api_result]['error_summary'], - raw_response.env[:api_result]['error']['reason'] - ) + # now while uploading a file dropbox returns 429 error code with none application/json content-type + # so raw_response.env[:api_result] is nil + error = if raw_response.env[:api_result] + DropboxApi::Errors::TooManyRequestsError.build( + raw_response.env[:api_result]['error_summary'], + raw_response.env[:api_result]['error']['reason'] + ) + else + DropboxApi::Errors::TooManyRequestsError.build( + 'Too many requests.', + { '.tag' => 'too_many_write_operations' } + ) + end error.retry_after = raw_response.headers['retry-after'].to_i diff --git a/spec/fixtures/vcr_cassettes/upload/too_many_write_operations.yml b/spec/fixtures/vcr_cassettes/upload/too_many_write_operations.yml index 28a851a1..16f97b89 100644 --- a/spec/fixtures/vcr_cassettes/upload/too_many_write_operations.yml +++ b/spec/fixtures/vcr_cassettes/upload/too_many_write_operations.yml @@ -316,7 +316,7 @@ http_interactions: Date: - Fri, 31 May 2019 21:25:32 GMT Content-Type: - - application/json + - text/javascript Transfer-Encoding: - chunked Connection: @@ -331,8 +331,7 @@ http_interactions: - noindex, nofollow, noimageindex body: encoding: UTF-8 - string: '{"error_summary": "too_many_write_operations/", "error": {"reason": - {".tag": "too_many_write_operations"}}}' + string: 'text' http_version: recorded_at: Fri, 31 May 2019 21:25:32 GMT - request: