def handle_error(r, expected_code):
    """
    Helper function to match reponse of a request to the expected status
    code

    :param r: This field is the response of request.
    :param expected_code: This field is the expected status code for the
        function.
    """
    code = r.status_code
    if code != expected_code:
        info = 'API response status code {}:\n{}'.format(code, r.content)
        raise Exception(info)
