import requests
import logging


def connect_to_endpoint(url, headers, params):
    """This function fetches tweets from specific twitter handle timelines
    Args:
        url: API endpoint to fetch tweets
        headers: Headers
        params: Additional parameters

    Returns:
        List of tweets as json payload
    """
    response = requests.request("GET", url, headers=headers, params=params)
    logging.info("Connected to ingestion endpoint")
    if response.status_code != 200:
        raise Exception(
            "Request returned an error: {} {}".format(
                response.status_code, response.text
            )
        )
    return response.json()