import requests


def check_response(response: requests.Response, comment: str, expected_code=200):
    """Check response status and returns content if exists. Will distinguish between JSON and the rest.
    Make sure what kind of body you are expecting.

    Args:
        response (requests.Response): The response object.
        comment (str): The string to be printed. Message will display like this:
            \"Request for <comment> successful/unsuccessful.\"
        expected_code (int, optional): Expected return code. Defaults to 200.

    Returns:
        bytes, JSON object or None: Returns the body of the requests.
    """
    if response.status_code == expected_code:
        print("Request for " + comment + " successful.")
        if response.headers['content-type'] == 'application/json':
            return response.json()
        else:
            return response.content
    else:
        print(
            f"Request for {comment} unsuccessful. Error code {response.status_code}.")
        return response.content