fix(leadmail): serialize payload to JSON before POST
Faraday's default request pipeline doesn't auto-serialize a Hash body
when Content-Type is application/json — the :url_encoded middleware only
kicks in for application/x-www-form-urlencoded. With our json content-
type, the Hash was passed through unchanged to Net::HTTP, which then
called body.bytesize for Content-Length and crashed with:
NoMethodError (undefined method 'bytesize' for an instance of Hash)
Bug was dormant until the previous commit (a00bcb204) wired
ActionMailer::Base.delivery_method = :leadmail correctly. Before that
fix, delivery_method was silently :smtp and this code never ran.
Serialize the payload explicitly with .to_json. Content-Type header is
already set on the Faraday client.
This commit is contained in:
@@ -7,7 +7,7 @@ class LeadmailDelivery
|
||||
|
||||
def deliver!(message)
|
||||
payload = build_payload(message)
|
||||
response = http_client.post('/emails/send', payload)
|
||||
response = http_client.post('/emails/send', payload.to_json)
|
||||
|
||||
unless response.success?
|
||||
raise LeadmailDeliveryError, "LeadMail API error: #{response.status} - #{response.body}"
|
||||
|
||||
Reference in New Issue
Block a user