class Helio::HelioClient::RequestLogContext

RequestLogContext stores information about a request that's begin made so that we can log certain information. It's useful because it means that we don't have to pass around as many parameters.

Attributes

api_id[RW]
api_token[RW]
api_version[RW]
body[RW]
idempotency_key[RW]
method[RW]
path[RW]
query_params[RW]
request_id[RW]

Public Instance Methods

dup_from_response(resp) click to toggle source

The idea with this method is that we might want to update some of context information because a response that we've received from the API contains information that's more authoritative than what we started with for a request. For example, we should trust whatever came back in a `Helio-Version` header beyond what configuration information that we might have had available.

# File lib/helio/helio_client.rb, line 467
def dup_from_response(resp)
  return self if resp.nil?

  # Faraday's API is a little unusual. Normally it'll produce a response
  # object with a `headers` method, but on error what it puts into
  # `e.response` is an untyped `Hash`.
  headers = if resp.is_a?(Faraday::Response)
              resp.headers
            else
              resp[:headers]
            end

  context = dup
  context.api_id = headers["X-API-ID"]
  context.api_version = headers["Helio-Version"]
  context.idempotency_key = headers["Idempotency-Key"]
  context.request_id = headers["Request-Id"]
  context
end