module Jekyll::Algolia::ErrorHandler
def self.record_too_big?(error, context = {})
means that one of the records is too big, so we'll try to give
Records cannot weight more that 10Kb. If we're getting this error it
context[:records] - list of records sent in the batch
Public: Check if the sent records are not too big
def self.record_too_big?(error, context = {}) details = error_hash(error.message) message = details['message'] return false if message !~ /^Record .* is too big .*/ # Getting the record size size, = /.*size=(.*) bytes.*/.match(message).captures size = Filesize.from("#{size} B").to_s('Kb') object_id = details['objectID'] # Getting record details record = Utils.find_by_key(context[:records], :objectID, object_id) probable_wrong_keys = readable_largest_record_keys(record) # Writing the full record to disk for inspection record_log_path = Logger.write_to_file( "jekyll-algolia-record-too-big-#{object_id}.log", JSON.pretty_generate(record) ) { 'object_id' => object_id, 'object_title' => record[:title], 'object_url' => record[:url], 'probable_wrong_keys' => probable_wrong_keys, 'record_log_path' => record_log_path, 'nodes_to_index' => Configurator.algolia('nodes_to_index'), 'size' => size, 'size_limit' => '10 Kb' } end