Closed jamonholmgren closed 10 years ago
This manifests itself in the gem because response.ok?
returns true even with bad credentials, by the way:
require 'nexmo'
nexmo = Nexmo::Client.new('WRONG', 'WRONG')
response = nexmo.send_message({:to => '12345678910', :from => '12345678910', :text => 'some text'})
puts response.instance_variable_get("@http_response").inspect
puts response.object
Response:
#<Net::HTTPOK 200 OK readbody=true>
{"message-count"=>"1", "messages"=>[{"status"=>"4", "error-text"=>"Bad Credentials"}]}
@jamonholmgren I agree it's not well designed, as a whole the Nexmo API is one of the most badly designed HTTP APIs I've come across. The good news is that the workaround already exists: if you use the send_message bang method (i.e. #send_message!
) that'll look inside the JSON payload and raise an exception if there's an error. You can see the logic here. Can you try and see if that works better?
Got it, thanks Tim!
Nexmo does something stupid when you provide invalid credentials.
This caused a hard-to-track-down bug in our Rails app.
I reached out to them and they said it was working as designed. O_o
This is a ridiculous response. HTTP 200 does not mean "server was reachable." I replied back to that effect.
In the meantime, should the Nexmo gem work around this by examining the message status?