mirror of
https://github.com/samsonjs/grape_logging.git
synced 2026-04-14 12:15:46 +00:00
27 lines
686 B
Ruby
27 lines
686 B
Ruby
module GrapeLogging
|
|
module Loggers
|
|
class Response < GrapeLogging::Loggers::Base
|
|
def parameters(request, response)
|
|
if response
|
|
{
|
|
response: serialized_response_body(response)
|
|
}
|
|
else
|
|
{}
|
|
end
|
|
end
|
|
|
|
private
|
|
# In some cases, response.body is not parseable by JSON.
|
|
# For example, if you POST on a PUT endpoint, response.body is egal to """".
|
|
# It's strange but it's the Grape behavior...
|
|
def serialized_response_body(response)
|
|
begin
|
|
response.body.map{ |body| JSON.parse(body) }
|
|
rescue => e
|
|
response.body
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|