<commit_before>module Atmosphere
  module Api
    class ApplicationController < ::ApplicationController
      include Atmosphere::Api::ApplicationControllerExt
      protect_from_forgery with: :null_session, if: :token_request?
      protect_from_forgery with: :exception, unless: :token_request?

      check_authorization

      include CancanStrongParams
      include Filterable

      rescue_from CanCan::AccessDenied do |exception|
        if current_user.nil?
          render_json_error('401 Unauthorized', status: :unauthorized)
        else
          render_json_error('403 Forbidden', status: :forbidden)
        end
      end

      rescue_from ActiveRecord::RecordNotFound do |exception|
        render_json_error('Record not found', status: :not_found)
      end

      rescue_from ActionController::ParameterMissing, Atmosphere::InvalidParameterFormat do |exception|
        render_json_error(exception.to_s, status: :unprocessable_entity)
      end

      rescue_from Atmosphere::Conflict do |exception|
        log_user_action "record conflict #{exception}"
        render_json_error(exception.to_s, status: :conflict, type: :conflict)
      end<commit_msg>Customization is added after user is authorized<commit_after>module Atmosphere
  module Api
    class ApplicationController < ::ApplicationController
      protect_from_forgery with: :null_session, if: :token_request?
      protect_from_forgery with: :exception, unless: :token_request?

      check_authorization

      include Atmosphere::Api::ApplicationControllerExt
      include CancanStrongParams
      include Filterable

      rescue_from CanCan::AccessDenied do |exception|
        if current_user.nil?
          render_json_error('401 Unauthorized', status: :unauthorized)
        else
          render_json_error('403 Forbidden', status: :forbidden)
        end
      end

      rescue_from ActiveRecord::RecordNotFound do |exception|
        render_json_error('Record not found', status: :not_found)
      end

      rescue_from ActionController::ParameterMissing, Atmosphere::InvalidParameterFormat do |exception|
        render_json_error(exception.to_s, status: :unprocessable_entity)
      end

      rescue_from Atmosphere::Conflict do |exception|
        log_user_action "record conflict #{exception}"
        render_json_error(exception.to_s, status: :conflict, type: :conflict)
      end
{'fraction_non_alphanumeric': 0.07052896725440806, 'fraction_numerical': 0.005037783375314861, 'mean_word_length': 3.718811881188119, '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': '4889153', 'n_tokens_mistral': 646, 'n_tokens_neox': 635, 'n_words': 153}