<commit_before>def error_hash(mesg, *params)
  {
    error_type: :error,
    params: params,
    source: caller[1..4],
    system: 'api',
    error_mesg: mesg
  }
end

def send_encoded_exception(api_exception)#request, error_object, *args)
  api_exception[:exception] = fake_exception(api_exception) unless api_exception[:exception].is_a?(Exception)
  if api_exception[:exception].is_a?(EnginesException)
   unless  api_exception[:exception].status.nil?
     status_code = api_exception[:exception].status
   else    
    if api_exception[:exception].level == :warning
      status_code = 405
    else
      status_code = 406
    end    
   end 
  end
  status_code = api_exception[:status] if api_exception.key?(:status)
  status_code = 500 if status_code.nil?
  if request.is_a?(String)
    error_mesg = {
      route: request,
      error_object: {}
    }
  else
    error_mesg = {
      route: request.fullpath,
      method: request.request_method,
      query: request.query_string,
      params: request.params,
      error_object: {}
    }
  end<commit_msg>wargin_hash helpers<commit_after>def error_hash(mesg, *params)
  {
    error_type: :error,
    params: params,
    source: caller[1..4],
    system: 'api',
    error_mesg: mesg
  }
end

def warning_hash(mesg, params = nil)
  r = error_hash(mesg, params)
  r [:error_type] = :warning
  r
end

def send_encoded_exception(api_exception)#request, error_object, *args)
  api_exception[:exception] = fake_exception(api_exception) unless api_exception[:exception].is_a?(Exception)
  if api_exception[:exception].is_a?(EnginesException)
    unless  api_exception[:exception].status.nil?
      status_code = api_exception[:exception].status
    else
      if api_exception[:exception].level == :warning
        status_code = 405
      else
        status_code = 406
      end
    end
  end
  status_code = api_exception[:status] if api_exception.key?(:status)
  status_code = 500 if status_code.nil?
  if request.is_a?(String)
    error_mesg = {
      route: request,
      error_object: {}
    }
  else
    error_mesg = {
      route: request.fullpath,
      method: request.request_method,
      query: request.query_string,
      params: request.params,
      error_object: {}
    }
  end
{'fraction_non_alphanumeric': 0.10725411659991099, 'fraction_numerical': 0.009790832220738763, 'mean_word_length': 3.3481624758220505, 'pattern_counts': {'":': 0, '<': 3, '<?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': '942825', 'n_tokens_mistral': 749, 'n_tokens_neox': 735, 'n_words': 144}