fix(leadmail): serialize payload to JSON before POST
Some checks failed
Lock Threads / action (push) Has been cancelled
Run Linux nightly installer / nightly (push) Has been cancelled
Mark stale issues and pull requests / stale (push) Has been cancelled

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:
netlas
2026-04-27 22:11:48 +03:00
parent 0839fbec79
commit 8df7a1192c

View File

@@ -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}"