Debugging api requests with Pry

I was debugging why I got back a 404 response from the Heroku Platform API.

Caused by Excon::Error::NotFound: Expected([200, 201, 202, 204, 206, 304, 429]) <=> Actual(404 Not Found)

Set a breakpoint on request to check what’s really happening in the API request:

break Excon::Connection#request

And that would show something like this:

From: /Users/justin/.rvm/gems/ruby-2.7.3@popmenu/gems/httplog-1.5.0/lib/httplog/adapters/excon.rb:29 Excon::Connection#request:

    27: def request(params, &block)
    28:   result = nil
 => 29:   bm = Benchmark.realtime do
    30:     result = orig_request(params, &block)
    31:   end
    32:
    33:   url = httplog_url(@data)
    34:   return result unless HttpLog.url_approved?(url)
    35:
    36:   headers = result[:headers] || {}
    37:
    38:   HttpLog.call(
    39:     method: params[:method],
    40:     url: url,
    41:     request_body: @data[:body],
    42:     request_headers: @data[:headers] || {},
    43:     response_code: result[:status],
    44:     response_body: result[:body],
    45:     response_headers: headers,
    46:     benchmark: bm,
    47:     encoding: headers['Content-Encoding'],
    48:     content_type: headers['Content-Type'],
    49:     mask_body: HttpLog.masked_body_url?(url)
    50:   )
    51:   result
    52: end

From there, I could debug inside of the request, and correlate that to the API docs: