Skip to content

Instantly share code, notes, and snippets.

@kml
Created December 13, 2016 22:41
Show Gist options
  • Save kml/4f39afba8d125c1ec004e964d823abbb to your computer and use it in GitHub Desktop.
Save kml/4f39afba8d125c1ec004e964d823abbb to your computer and use it in GitHub Desktop.
Log responses from RestClient
module RestClientLogResponsePatch
def process_result(res, &block)
response = super
log_response_with_body(response) unless res.is_a?(Net::HTTPRedirection)
response
rescue RestClient::Exception => exception
log_response_with_body(exception.response)
raise exception
end
private
def log_response_with_body(response)
return unless RestClient.log
RestClient.log << "RestClient.#{method} #{response.code} #{redacted_url.inspect} => #{response.body.truncate(1024)}"
end
end
RestClient::Request.prepend(RestClientLogResponsePatch)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment