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...
1 parent e0913fb commit ec56cf48e2aa62fc262576f40a1da3bd4eaaf95d Fiona Tay & Will Read committed Jul 26, 2012
Showing with 7 additions and 3 deletions.
  1. +1 −1 lib/twilio-ruby/rest/client.rb
  2. +6 −2 test/twilio_spec.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
- 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 object['message'], object['code']
@@ -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:\/\/\//, :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 ='someSid', 'someToken')
+'/phone_number', twilio).delete
it 'should set up a new client instance with the given sid and token' do

0 comments on commit ec56cf4

Please sign in to comment.