module Jekyll::Algolia::ErrorHandler

def self.record_too_big?(error, context = {})

informations about it so the user can debug it.
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 to push

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").pretty
  object_id = details['objectID']
  # Getting record details
  record = Utils.find_by_key(context[:records], :objectID, object_id)
  {
    'object_id' => object_id,
    'object_title' => record[:title],
    'object_url' => record[:url],
    'object_hint' => record[:content][0..100],
    'nodes_to_index' => Configurator.algolia('nodes_to_index'),
    'size' => size,
    'size_limit' => '10 Kb'
  }
end