<commit_before>module Core::Repository
  module CMS
    class CMS < Core::Repository::Base
      def initialize(options = {})
        self.connection = Core::Registry::Connection[:cms]
        self.fallback_repository = options[:fallback]
      end

      def find(id)
        resource_url = '%{locale}/%{page_type}/%{id}.json' % { locale: I18n.locale, page_type: resource_name, id: id }
        response = connection.get(resource_url)
        AttributeBuilder.build(response)
      rescue => e
        Rails.logger.error(e.message)
        Rails.logger.info('Fallback to #{fallback_repository}')
        fallback_repository.find(id)
      end

      def resource_name
        self.class.name.split('::')[-2].underscore
      end

      private

      attr_accessor :connection, :fallback_repository
    end
  end
end<commit_msg>Add a better error message when CMS returns error<commit_after>module Core::Repository
  module CMS
    class CMS < Core::Repository::Base
      def initialize(options = {})
        self.connection = Core::Registry::Connection[:cms]
        self.fallback_repository = options[:fallback]
      end

      def find(id)
        resource_url = '%{locale}/%{page_type}/%{id}.json' % { locale: I18n.locale, page_type: resource_name, id: id }
        response = connection.get(resource_url)
        AttributeBuilder.build(response)
      rescue => e
        Rails.logger.error("Tried to fetch from Contento. Error message: #{e.message}")
        fallback_repository.find(id)
      end

      def resource_name
        self.class.name.split('::')[-2].underscore
      end

      private

      attr_accessor :connection, :fallback_repository
    end
  end
end
{'fraction_non_alphanumeric': 0.11428571428571428, 'fraction_numerical': 0.0035714285714285713, 'mean_word_length': 2.8378995433789953, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '7196168', 'n_tokens_mistral': 499, 'n_tokens_neox': 484, 'n_words': 103}