import logging


def process_response(response, records):
    """ Examines the response from PutRecords, returning any records that couldn't be sent.
        """
    if response['FailedRecordCount'] == 0:
        return []

    result = []
    dropped_record_count = 0
    for ii in range(len(response['Records'])):
        entry = response['Records'][ii]
        errorCode = entry.get('ErrorCode')
        if errorCode == 'ProvisionedThroughputExceededException':
            result.append(records[ii])
        elif errorCode:
            dropped_record_count += 1

    if dropped_record_count > 0:
        logging.warn(f'dropped {dropped_record_count} records due to Kinesis internal errors')
    if len(result) > 0:
        logging.info(f'requeueing {len(result)} records due to throughput-exceeded')

    return result