Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Handling empty response when deleting

When working with deleting phone numbers we got a MultiJson decode error
and needed to better handle the case where the body was an empty string.

We also began the test by disallowing external connections to provide
a clearer error message when an external call is being made and it needs
to be faked out.
  • Loading branch information...
commit ec56cf48e2aa62fc262576f40a1da3bd4eaaf95d 1 parent e0913fb
Fiona Tay & Will Read authored
Showing with 7 additions and 3 deletions.
  1. +1 −1  lib/twilio-ruby/rest/client.rb
  2. +6 −2 test/twilio_spec.rb
View
2  lib/twilio-ruby/rest/client.rb
@@ -218,7 +218,7 @@ def connect_and_send(request) # :doc:
rescue Exception
if retries_left > 0 then retries_left -= 1; retry else raise end
end
- object = MultiJson.load response.body if response.body.present?
+ object = MultiJson.load response.body unless response.body.empty?
if response.kind_of? Net::HTTPClientError
raise Twilio::REST::RequestError.new object['message'], object['code']
end
View
8 test/twilio_spec.rb
@@ -3,9 +3,13 @@
require 'fakeweb'
require 'rack'
+FakeWeb.allow_net_connect = false
+
describe Twilio::REST::Client do
- before :all do
- FakeWeb.register_uri(:any, %r/http:\/\/api.twilio.com\//, :body => '{"message": "You tried to reach Twilio"}')
+ it 'should not raise an error if the response body is empty' do
+ FakeWeb.register_uri(:any, %r/api\.twilio\.com/, :body => '')
+ twilio = Twilio::REST::Client.new('someSid', 'someToken')
+ Twilio::REST::IncomingPhoneNumber.new('/phone_number', twilio).delete
end
it 'should set up a new client instance with the given sid and token' do
Please sign in to comment.
Something went wrong with that request. Please try again.