import requests
import json


def update_task_id(task_id=None, gman_url=None, status=None, message=None):
    """
    Updates a taskID status and/or message
    :param task_id: TaskID to update as a string
    :param gman_url: GMan endpoint as a string
    :param status: The status to apply to the task
    :param message: The message to apply to the task
    :return: JSON response from gman
    """
    try:
        data = {"message": message, "status": status}
        r = requests.put(f"{gman_url}/task/{task_id}", data=json.dumps(data))
        r.raise_for_status()
    except requests.exceptions.HTTPError as e:
        raise requests.exceptions.HTTPError(
            f"GMan returned with a bad status code. \n\n{e}"
        )
    except requests.exceptions.RequestException as e:
        raise requests.exceptions.RequestException(
            f"Failed to update taskID {task_id}. \n\n{e}"
        )
    return r.json()