<commit_before>module GrapeLogging
  module Loggers
    class Response < GrapeLogging::Loggers::Base
      def parameters(request, response)
        {
          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<commit_msg>response.body is sometimes too strange to be parse by JSON, BIS<commit_after>module GrapeLogging
  module Loggers
    class Response < GrapeLogging::Loggers::Base
      def parameters(request, response)
        {
          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
{'fraction_non_alphanumeric': 0.0770392749244713, 'fraction_numerical': 0.0, 'mean_word_length': 2.125, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '350834', 'n_tokens_mistral': 377, 'n_tokens_neox': 364, 'n_words': 121}