def HandleAPIError(error, operation):
  """Makes an exemption for exemptable PolicyViolationErrors.

  Args:
    error: the error associated with the given operation.
    operation: the operation associated with the given error.

  Returns:
    A boolean that is True if the given error was an exemptable
    PolicyViolationError; otherwise, returns False.
  """
  is_exemptable = False

  # Determine if the operation can be resubmitted with an exemption request.
  if error['ApiError.Type'] == 'PolicyViolationError':
    expanded_text_ad = operation['operand']['ad']
    is_exemptable = (error['isExemptable'] if 'isExemptable' in error else
                     False)
    print ('Ad with headline "%s - %s" violated %s policy "%s".' %
           (expanded_text_ad['headlinePart1'],
            expanded_text_ad['headlinePart2'],
            'exemptable' if is_exemptable else 'non-exemptable',
            error['externalPolicyName']))

  if is_exemptable:
    # Add exemption request to the operation.
    print ('Adding exemption request for policy name \'%s\' on text \'%s\'.'
           % (error['key']['policyName'], error['key']['violatingText']))
    if 'exemptionRequests' not in operation:
      operation['exemptionRequests'] = []
    operation['exemptionRequests'].append({'key': error['key']})

  return is_exemptable