<commit_before>module Api
  class ApplicationController < ActionController::Base
    protect_from_forgery with: :null_session

    before_filter :authenticate_user_from_token!
    check_authorization

    include CancanStrongParams
    include Filterable

    rescue_from CanCan::AccessDenied do |exception|
      if current_user.nil?
        render json: {message: '401 Unauthorized'}, status: :unauthorized
      else
        render json: {message: '403 Forbidden'}, status: :forbidden
      end
    end

    rescue_from ActiveRecord::RecordNotFound do |exception|
      render json: {message: 'Record not found'}, status: :not_found
    end

    rescue_from ActionController::ParameterMissing do |exception|
      render json: {message: exception.to_s}, status: :bad_request
    end

    rescue_from Air::Conflict do |exception|
      log_user_action "record conflict #{exception}"
      render json: {message: exception}, status: :conflict
    end

    rescue_from ActiveRecord::RecordInvalid do |exception|
      render_error exception.record
    end

    protected
    def render_error(model_obj)
      log_user_action "record invalid #{model_obj.errors.to_json}"
      render json: model_obj.errors, status: :unprocessable_entity<commit_msg>changed parameter missing error mapping to 422<commit_after>module Api
  class ApplicationController < ActionController::Base
    protect_from_forgery with: :null_session

    before_filter :authenticate_user_from_token!
    check_authorization

    include CancanStrongParams
    include Filterable

    rescue_from CanCan::AccessDenied do |exception|
      if current_user.nil?
        render json: {message: '401 Unauthorized'}, status: :unauthorized
      else
        render json: {message: '403 Forbidden'}, status: :forbidden
      end
    end

    rescue_from ActiveRecord::RecordNotFound do |exception|
      render json: {message: 'Record not found'}, status: :not_found
    end

    rescue_from ActionController::ParameterMissing do |exception|
      render json: {message: exception.to_s}, status: :unprocessable_entity
    end

    rescue_from Air::Conflict do |exception|
      log_user_action "record conflict #{exception}"
      render json: {message: exception}, status: :conflict
    end

    rescue_from ActiveRecord::RecordInvalid do |exception|
      render_error exception.record
    end

    protected
    def render_error(model_obj)
      log_user_action "record invalid #{model_obj.errors.to_json}"
      render json: model_obj.errors, status: :unprocessable_entity
{'fraction_non_alphanumeric': 0.07407407407407407, 'fraction_numerical': 0.00591016548463357, 'mean_word_length': 3.8921001926782273, 'pattern_counts': {'":': 0, '<': 5, '<?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': '6951035', 'n_tokens_mistral': 706, 'n_tokens_neox': 688, 'n_words': 197}