diff --git a/lib/external_credential/twitter.rb b/lib/external_credential/twitter.rb index a2db7d7dd..9adda00e0 100644 --- a/lib/external_credential/twitter.rb +++ b/lib/external_credential/twitter.rb @@ -29,11 +29,14 @@ class ExternalCredential::Twitter begin request_token = consumer.get_request_token(oauth_callback: ExternalCredential.callback_url('twitter')) rescue => e - if e.message == '403 Forbidden' - raise "#{e.message}, maybe credentials wrong or callback_url for application wrong configured." + case e.message + when '401 Authorization Required' + raise "#{e.message} (Invalid credentials may be to blame.)" + when '403 Forbidden' + raise "#{e.message} (Your app's callback URL configuration on developer.twitter.com may be to blame.)" + else + raise end - - raise e end { diff --git a/spec/requests/external_credentials_spec.rb b/spec/requests/external_credentials_spec.rb index 7ecf2e06b..1d6756995 100644 --- a/spec/requests/external_credentials_spec.rb +++ b/spec/requests/external_credentials_spec.rb @@ -224,7 +224,9 @@ RSpec.describe 'External Credentials', type: :request do include_examples 'for failure cases' do let(:status) { :ok } - let(:error_message) { '401 Authorization Required' } + let(:error_message) { <<~ERR.chomp } + 401 Authorization Required (Invalid credentials may be to blame.) + ERR end end @@ -234,7 +236,7 @@ RSpec.describe 'External Credentials', type: :request do include_examples 'for failure cases' do let(:status) { :ok } let(:error_message) { <<~ERR.chomp } - 403 Forbidden, maybe credentials wrong or callback_url for application wrong configured. + 403 Forbidden (Your app's callback URL configuration on developer.twitter.com may be to blame.) ERR end end @@ -343,7 +345,9 @@ RSpec.describe 'External Credentials', type: :request do include_examples 'for failure cases' do let(:status) { :internal_server_error } - let(:error_message) { '401 Authorization Required' } + let(:error_message) { <<~ERR.chomp } + 401 Authorization Required (Invalid credentials may be to blame.) + ERR end end @@ -353,7 +357,7 @@ RSpec.describe 'External Credentials', type: :request do include_examples 'for failure cases' do let(:status) { :internal_server_error } let(:error_message) { <<~ERR.chomp } - 403 Forbidden, maybe credentials wrong or callback_url for application wrong configured. + 403 Forbidden (Your app's callback URL configuration on developer.twitter.com may be to blame.) ERR end end