<commit_before>module LeanplumApi
  class BadResponseError < RuntimeError; end
  class ResourceNotFoundError < RuntimeError; end

  class ResponseValidation < Faraday::Middleware
    Faraday::Request.register_middleware(leanplum_response_validation: self)

    def call(environment)
      operations = nil

      if environment.body
        operations = environment.body[:data] if environment.body[:data] && environment.body[:data].is_a?(Array)
        environment.body = environment.body.to_json
      end

      @app.call(environment).on_complete do |response|
        fail ResourceNotFoundError if response.status == 404
        fail BadResponseError, response.inspect unless response.status == 200 && response.body['response']
        fail BadResponseError, "No :success key in #{response.inspect}!" unless response.body['response'].is_a?(Array) && response.body['response'].first.has_key?('success')<commit_msg>Exception message<commit_after>module LeanplumApi
  class BadResponseError < RuntimeError; end
  class ResourceNotFoundError < RuntimeError; end

  class ResponseValidation < Faraday::Middleware
    Faraday::Request.register_middleware(leanplum_response_validation: self)

    def call(environment)
      operations = nil

      if environment.body
        operations = environment.body[:data] if environment.body[:data] && environment.body[:data].is_a?(Array)
        environment.body = environment.body.to_json
      end

      @app.call(environment).on_complete do |response|
        fail ResourceNotFoundError, response.inspect if response.status == 404
        fail BadResponseError, response.inspect unless response.status == 200 && response.body['response']
        fail BadResponseError, "No :success key in #{response.inspect}!" unless response.body['response'].is_a?(Array) && response.body['response'].first.has_key?('success')
{'fraction_non_alphanumeric': 0.10571736785329018, 'fraction_numerical': 0.006472491909385114, 'mean_word_length': 4.488165680473373, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 3, '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': '1460057', 'n_tokens_mistral': 497, 'n_tokens_neox': 480, 'n_words': 109}