mailjet-gem icon indicating copy to clipboard operation
mailjet-gem copied to clipboard

Possible bug in the `Mailjet::Send.create` method

Open eduardoborba opened this issue 2 years ago • 0 comments

Hi everyone,

I noticed an undefined method '[]' for nil:NilClass error coming from the mailjet gem when looking into the logs in our application. Looking into the logs, I noticed that the request to send the email was triggered twice, as the first request was taking too long (more than 60 seconds) and our internal retry mechanism thought it had failed. The first request was successful though, besides the delay, and the second request also took very long but failed with the undefined method error I mentioned before.

Below you can see the stacktrace:

'/mail_service/bundle/ruby/2.6.0/gems/mailjet-1.6.0/lib/mailjet/connection.rb:90:in `handle_exception'
'/mail_service/bundle/ruby/2.6.0/gems/mailjet-1.6.0/lib/mailjet/connection.rb:77:in `rescue in handle_api_call'
'/mail_service/bundle/ruby/2.6.0/gems/mailjet-1.6.0/lib/mailjet/connection.rb:63:in `handle_api_call'
'/mail_service/bundle/ruby/2.6.0/gems/mailjet-1.6.0/lib/mailjet/connection.rb:50:in `post'
'/mail_service/bundle/ruby/2.6.0/gems/mailjet-1.6.0/lib/mailjet/resource.rb:255:in `save'
'/mail_service/bundle/ruby/2.6.0/gems/mailjet-1.6.0/lib/mailjet/resource.rb:278:in `save!'
'/mail_service/bundle/ruby/2.6.0/gems/mailjet-1.6.0/lib/mailjet/resource.rb:116:in `block in create'
'/mail_service/bundle/ruby/2.6.0/gems/mailjet-1.6.0/lib/mailjet/resource.rb:115:in `tap'
'/mail_service/bundle/ruby/2.6.0/gems/mailjet-1.6.0/lib/mailjet/resource.rb:115:in `create'
'/mail_service/logic/providers/mailjet.rb:22:in `send_mail'

In the end it was not a big issue, as the email was sent afterall. But something weird happened inside of the gem code to throw this undefined method error. I don’t have the information of what exactly was returned by mailjet in the response, but it seems like the code was expecting it.

eduardoborba avatar Mar 24 '22 12:03 eduardoborba