diff --git a/lib/mangopay.rb b/lib/mangopay.rb index 7a1bf1e..f29a627 100644 --- a/lib/mangopay.rb +++ b/lib/mangopay.rb @@ -214,7 +214,13 @@ def request(method, url, params={}, filters={}, headers_or_idempotency_key = nil raise MangoPay::ResponseError.new(uri, '408', {'Message' => 'Request Timeout'}) if res.nil? # decode json data - data = res.body.to_s.empty? ? {} : JSON.load(res.body.to_s) + begin + data = res.body.to_s.empty? ? {} : JSON.load(res.body.to_s) + rescue MultiJson::ParseError + details = {} + details['Message'] = res.body + raise MangoPay::ResponseError.new(uri, res.code, details) + end unless res.is_a?(Net::HTTPOK) raise MangoPay::ResponseError.new(uri, res.code, data) @@ -298,12 +304,17 @@ def do_request_with_log(http, req, uri) res ensure line = "#{log_severity(res)} #{line}" + if time.nil? + time_log = "[Unknown ms]" + else + time_log = "[#{(time * 1000).round(1)}ms]" + end if res.nil? params = '' - line += "\n [#{(time * 1000).round(1)}ms] 408 Request Timeout #{params}\n" + line += "\n #{time_log} 408 Request Timeout #{params}\n" else params = FilterParameters.response(res.body) - line += "\n [#{(time * 1000).round(1)}ms] #{res.code} #{params}\n" + line += "\n #{time_log} #{res.code} #{params}\n" end logger.info { line } end diff --git a/spec/mangopay/card_registration_spec.rb b/spec/mangopay/card_registration_spec.rb index 3c030fe..16a4bae 100644 --- a/spec/mangopay/card_registration_spec.rb +++ b/spec/mangopay/card_registration_spec.rb @@ -6,7 +6,6 @@ it 'creates a new card registration' do created = new_card_registration expect(created['Id']).not_to be_nil - expect(created['Id'].to_i).to be > 0 expect(created['AccessKey']).not_to be_nil expect(created['PreregistrationData']).not_to be_nil expect(created['CardRegistrationURL']).not_to be_nil @@ -51,7 +50,6 @@ # card id filled-in... expect(card_id).not_to be_nil - expect(card_id.to_i).to be > 0 # ...and points to existing (newly created) card card = MangoPay::Card.fetch(card_id) diff --git a/spec/mangopay/preauthorization_spec.rb b/spec/mangopay/preauthorization_spec.rb index 277dd8f..3f7fe71 100644 --- a/spec/mangopay/preauthorization_spec.rb +++ b/spec/mangopay/preauthorization_spec.rb @@ -7,7 +7,6 @@ cardreg = new_card_registration_completed created = new_card_preauthorization expect(created['Id']).not_to be_nil - expect(created['Id'].to_i).to be > 0 expect(created['CardId']).to eq(cardreg['CardId']) expect(created['AuthorId']).to eq(new_natural_user["Id"]) expect(created['PayInId']).to be_nil diff --git a/spec/mangopay/user_spec.rb b/spec/mangopay/user_spec.rb index b42c089..083c15a 100644 --- a/spec/mangopay/user_spec.rb +++ b/spec/mangopay/user_spec.rb @@ -144,7 +144,6 @@ fetched = MangoPay::Card.fetch(card['CardId']) expect(fetched['Id']).not_to be_nil - expect(fetched['Id'].to_i).to be > 0 expect(fetched['UserId']).to eq(new_natural_user["Id"]) expect(fetched['Currency']).to eq('EUR') end