Skip to content
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

Uses Twilio::REST::RestError when a page fails to load #397

Merged
merged 1 commit into from Apr 20, 2018

Conversation

philnash
Copy link
Contributor

This follows on from #391.

With the following code:

require './lib/twilio-ruby'

# We'll use a valid SID
account_sid = ENV['TWILIO_ACCOUNT_SID']
# But we'll use an invalid auth token
client = Twilio::REST::Client.new account_sid, "not_my_auth_token"
client.api.account.messages.list

the error message looks like:

/Users/pnash/projects/ruby-projects/twilio-ruby/lib/twilio-ruby/framework/page.rb:32:in `process_response': Unable to fetch page (Twilio::REST::TwilioError)
	from /Users/pnash/projects/ruby-projects/twilio-ruby/lib/twilio-ruby/framework/page.rb:22:in `initialize'
	from /Users/pnash/projects/ruby-projects/twilio-ruby/lib/twilio-ruby/rest/api/v2010/account/message.rb:212:in `initialize'
	from /Users/pnash/projects/ruby-projects/twilio-ruby/lib/twilio-ruby/rest/api/v2010/account/message.rb:181:in `new'
	from /Users/pnash/projects/ruby-projects/twilio-ruby/lib/twilio-ruby/rest/api/v2010/account/message.rb:181:in `page'
	from /Users/pnash/projects/ruby-projects/twilio-ruby/lib/twilio-ruby/rest/api/v2010/account/message.rb:127:in `stream'
	from /Users/pnash/projects/ruby-projects/twilio-ruby/lib/twilio-ruby/rest/api/v2010/account/message.rb:97:in `list'
	from test.rb:11:in `<main>'

But with this change looks like:

/Users/pnash/projects/ruby-projects/twilio-ruby/lib/twilio-ruby/framework/page.rb:32:in `process_response': [HTTP 401] 20003 : Unable to fetch page (Twilio::REST::RestError)
Authenticate
Your AccountSid or AuthToken was incorrect.
https://www.twilio.com/docs/errors/20003

	from /Users/pnash/projects/ruby-projects/twilio-ruby/lib/twilio-ruby/framework/page.rb:22:in `initialize'
	from /Users/pnash/projects/ruby-projects/twilio-ruby/lib/twilio-ruby/rest/api/v2010/account/message.rb:212:in `initialize'
	from /Users/pnash/projects/ruby-projects/twilio-ruby/lib/twilio-ruby/rest/api/v2010/account/message.rb:181:in `new'
	from /Users/pnash/projects/ruby-projects/twilio-ruby/lib/twilio-ruby/rest/api/v2010/account/message.rb:181:in `page'
	from /Users/pnash/projects/ruby-projects/twilio-ruby/lib/twilio-ruby/rest/api/v2010/account/message.rb:127:in `stream'
	from /Users/pnash/projects/ruby-projects/twilio-ruby/lib/twilio-ruby/rest/api/v2010/account/message.rb:97:in `list'
	from test.rb:11:in `<main>'`

This relies on the work done in #391 as it really just uses the Twilio::REST::RestError in place of the Twilio::REST::TwilioError when it is raised in response to a non 200 status code in Twilio::REST::Page#process_response.

The rest of the work just ensures that anyone using the now defunct body method in the Twilio::REST::TwilioError doesn't end up raising NoMethodErrors instead. It no longer makes sense for Twilio::REST::TwilioError to have a body, but since it did before this change I don't want to break anything. Read more about the actual thought process for this in the comments to #391.

@philnash
Copy link
Contributor Author

@efossier following up after #391. What do you think?

Copy link
Contributor

@codejudas codejudas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 I like the improved messaging

@codejudas codejudas merged commit ce7c025 into twilio:master Apr 20, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants