nylas/nylas-ruby

NoMethodError when calling `NewMessage#send!`

Closed this issue · 7 comments

This is mostly a duplicate of #261, but the bug is still happening.

When we call #send! on a NewMessage instance, and the API returns a 502 or 504 (these are the error codes where we noticed the bug), this gem is raising a NoMethodError because we are calling .merge(api: api) in a RestClient::Response object.

The API should check if we can or not merge the API data on the response, because it might not always be a Message.

@rafaeelaudibert Thank you for opening this issue, we will investigate and get back to you with any findings!

@rafaeelaudibert Just trying to reproduce the issue, which version of the Nylas Ruby SDK gem are you using?

Hey @mrashed-dev, thanks for looking into it!

We are on 5.1, but I checked the code and I think this should be reproducible in the latest version as well.

Our minimum reproducible event is pretty simple:

Nylas::NewMessage.new(*args).send!

Then, if the response is 502 or 504 (haven't received a 500 to confirm) we receive this error back.

@rafaeelaudibert Interesting, I wasn't able to reproduce this even by mocking the server response locally -- 502 and 504, it gets caught on http_client.rb:227 before it returns the response and attempts to merge. However, it's never a bad idea to do a proper check before attempting to do something like merging, so now we ensure that NewMessage#send! checks the API response data and ensures it's a Hash before it attempts to merge and create a new Message type, else it will through a RuntimeError. Also updated the method documentation to reflect this change. Once it's merged we'll release a patch release soon with the fix!

@rafaeelaudibert This fix is now available in v5.9.1!

Thanks! Once we update to the newest version I will circle back to you.

Thanks again for being so fast with this :)

@rafaeelaudibert It's our pleasure! Thanks for opening this issue and being so patient with it. Don't hesitate to open an issue if you encounter anything else!