def _extract_reason(kw):
    """
    Internal helper. Extracts a reason (possibly both reasons!) from
    the kwargs for a circuit failed or closed event.
    """
    try:
        reason = kw['REASON']
        try:
            reason = '{}, {}'.format(reason, kw['REMOTE_REASON'])
        except KeyError:
            pass
    except KeyError:
        reason = 'unknown'
    return reason
