mirror of
https://github.com/samsonjs/grape_logging.git
synced 2026-03-25 08:55:47 +00:00
response.body is sometimes too strange to be parse by JSON
This commit is contained in:
parent
b8bd70e57b
commit
918cba5c2d
1 changed files with 13 additions and 1 deletions
|
|
@ -3,9 +3,21 @@ module GrapeLogging
|
|||
class Response < GrapeLogging::Loggers::Base
|
||||
def parameters(request, response)
|
||||
{
|
||||
response: response.body
|
||||
response: serialized_response_body(response)
|
||||
}
|
||||
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
|
||||
""
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Reference in a new issue