Created
December 13, 2016 22:41
-
-
Save kml/4f39afba8d125c1ec004e964d823abbb to your computer and use it in GitHub Desktop.
Log responses from RestClient
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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