Skip to content

Error responses lose their body when raise_error closes the connection #8

Description

@lineoffligbot

API#http enables the http gem's raise_error feature, which raises HTTP::StatusError from wrap_response before the response body is read. HTTP::Client#perform then rescues, closes the connection, and re-raises (http 5.3.1, client.rb:92-94), so e.response.body.to_s is empty in any downstream rescue. Callers that log the error body get bare messages like "HTTP 400" with no detail.

Seen in production in pulsify-core (lineofflight/pulsify-core#1159): every Ads API 400 surfaced without its JSON error payload, making failures undiagnosable.

  • Affects both builder branches: use(:raise_error) and use(raise_error: { ignore: [429] })
  • Suggested fix: a custom feature that flushes the body (response.flush) before raising, replacing stock raise_error
  • response.flush memoizes the body into the response, so it survives the connection close

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions