<commit_before># frozen_string_literal: true

require 'i18n'
require 'tzispa/utils/string'

module Tzispa
  module Api
    module HandlerError

      using Tzispa::Utils::TzString

      HANDLER_OK = :ok

      def error?
        @error && @error != HANDLER_OK
      end

      def message
        I18n.t(error_id, default: error.to_s) if error
      end

      def error_id
        "#{self.class.name.dottize}.#{error}" if error
      end

      def http_bad_request(error = nil)
        error_status error || :bad_requuest, 400
      end

      def http_unauthorized(error = nil)
        error_status error || :unauthorized, 401
      end

      def http_forbidden(error = nil)
        error_status error || :forbidden, 403
      end

      def http_not_found(error = nil)
        error_status error || :not_found, 404
      end

      def http_not_aceptable(error = nil)
        error_status error || :not_acceptable, 406
      end

      def http_conflict(error = nil)
        error_status error || :conflict, 409
      end

      def http_gone(error = nil)
        error_status error || :gone, 410
      end

      def http_token_required(error = nil)
        error_status error || :token_required, 499
      end

      def http_server_error(error = nil)
        error_status error || :internal_server_error, 500
      end

      def http_not_implemented(error = nil)
        error_status error || :not_implemented, 501
      end

      def http_bad_gateway(error = nil)
        error_status error || :bad_gateway, 502
      end

      def http_service_unavailable(error = nil)
        error_status error || :service_unavailable, 503
      end

    end<commit_msg>added error_log method<commit_after># frozen_string_literal: true

require 'i18n'
require 'tzispa/utils/string'

module Tzispa
  module Api
    module HandlerError

      using Tzispa::Utils::TzString

      HANDLER_OK = :ok

      def error?
        @error && @error != HANDLER_OK
      end

      def message
        I18n.t(error_id, default: error.to_s) if error
      end

      def error_id
        "#{self.class.name.dottize}.#{error}" if error
      end

      def error_log(error)
        context.logger.error "#{error}\n\n#{error.backtrace if error.respond_to?(:backtrace)}"
      end

      def http_bad_request(msg = nil)
        error_status msg || :bad_request, 400
      end

      def http_unauthorized(msg = nil)
        error_status msg || :unauthorized, 401
      end

      def http_forbidden(msg = nil)
        error_status msg || :forbidden, 403
      end

      def http_not_found(msg = nil)
        error_status msg || :not_found, 404
      end

      def http_not_aceptable(msg = nil)
        error_status msg || :not_acceptable, 406
      end

      def http_conflict(msg = nil)
        error_status msg || :conflict, 409
      end

      def http_gone(msg = nil)
        error_status msg || :gone, 410
      end

      def http_token_required(msg = nil)
        error_status msg || :token_required, 499
      end

      def http_server_error(msg = nil)
        error_status msg || :internal_server_error, 500
      end

      def http_not_implemented(msg = nil)
        error_status msg || :not_implemented, 501
      end

      def http_bad_gateway(msg = nil)
        error_status msg || :bad_gateway, 502
      end

      def http_service_unavailable(msg = nil)
        error_status msg || :service_unavailable, 503
      end

    end
{'fraction_non_alphanumeric': 0.07927717866511222, 'fraction_numerical': 0.023316817254444767, 'mean_word_length': 2.2469252601702934, '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': '4501276', 'n_tokens_mistral': 1180, 'n_tokens_neox': 1065, 'n_words': 276}