Skip to content

Commit b2b14d8

Browse files
authored
Merge pull request #87 from Jesus/expired-access-token
Implement ExpiredAccessTokenError
2 parents 2973f13 + bec912e commit b2b14d8

File tree

5 files changed

+70
-0
lines changed

5 files changed

+70
-0
lines changed

lib/dropbox_api.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@
9191
require 'dropbox_api/errors/create_folder_error'
9292
require 'dropbox_api/errors/create_shared_link_with_settings_error'
9393
require 'dropbox_api/errors/download_error'
94+
require 'dropbox_api/errors/expired_access_token_error'
9495
require 'dropbox_api/errors/sharing_file_access_error'
9596
require 'dropbox_api/errors/sharing_user_error'
9697
require 'dropbox_api/errors/file_member_action_error'

lib/dropbox_api/endpoints/base.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ def process_response(raw_response)
2424
# Status code 409 is "Endpoint-specific error". We need to look at
2525
# the response body to build an exception.
2626
build_result(raw_response.env[:api_result])
27+
when 401
28+
raise DropboxApi::Errors::ExpiredAccessTokenError.build(
29+
raw_response.env[:api_result]['error_summary'],
30+
raw_response.env[:api_result]['error']
31+
)
2732
when 429
2833
error = DropboxApi::Errors::TooManyRequestsError.build(
2934
raw_response.env[:api_result]['error_summary'],
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# frozen_string_literal: true
2+
module DropboxApi::Errors
3+
class ExpiredAccessTokenError < BasicError
4+
end
5+
end

spec/client_spec.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,13 @@ module DropboxApi
3333
Faraday::Adapter::NetHttpPersistent
3434
))
3535
end
36+
37+
it 'will raise on 401 if there is no refresh token', cassette: 'client/raise_on_401' do
38+
client = Client.new("MOCK_EXPIRED_AUTHORIZATION_BEARER")
39+
40+
expect do
41+
client.list_folder ""
42+
end.to raise_error(DropboxApi::Errors::ExpiredAccessTokenError)
43+
end
3644
end
3745
end

spec/fixtures/vcr_cassettes/client/raise_on_401.yml

Lines changed: 51 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)