You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: api_error_handler.rb
    path of file: ./repos/api_error_handler/lib
    
    the code of the file until where you have to start completion: # frozen_string_literal: true

require
    
  def handle_api_errors(options = {})
    format = options.fetch(:format, :json)
    error_reporter = ErrorReporter.new(options[:error_reporter])
    serializer_options = SERIALIZER_OPTIONS.merge(
      options.slice(*SERIALIZER_OPTIONS.keys)
    )

    serializer_class = options[:serializer] || SERIALIZERS_BY_FORMAT.fetch(format)
    content_type = options[:content_type] || CONTENT_TYPE_BY_FORMAT[format]
    rescue_from StandardError do |error|
      status = ActionDispatch::ExceptionWrapper.rescue_responses[error.class.to_s]

      error_id = ErrorIdGenerator.run(options[:error_id])
      error_reporter.report(error, error_id: error_id)

      serializer = serializer_class.new(error, status)
      response_body = serializer.serialize(
        serializer_options.merge(error_id: error_id)
      )

      render(
        serializer.render_format => response_body,
        content_type: content_type,
        status: status
      )
    rescue
      raise error
    end
  end