import requests


def _return_response_and_status_code(response, json_results=True):
    """ Output the requests response content or content as json and status code

    :rtype : dict
    :param response: requests response object
    :param json_results: Should return JSON or raw content
    :return: dict containing the response content and/or the status code with error string.
    """
    if response.status_code == requests.codes.ok:
        return dict(results=response.json() if json_results else response.content, response_code=response.status_code)
    elif response.status_code == 400:
        return dict(
            error='package sent is malformed.',
            response_code=response.status_code)
    elif response.status_code == 404:
        return dict(error='Requested URL not found.', response_code=response.status_code)

    else:
        return dict(response_code=response.status_code)