def exception_is_4xx(exception):
    """Returns True if exception is in the 4xx range."""
    if not hasattr(exception, 'response'):
        return False
    if exception.response is None:
        return False
    if not hasattr(exception.response, 'status_code'):
        return False
    return 400 <= exception.response.status_code < 500
