from bs4 import BeautifulSoup


def parse_response_error(html_text: str) -> str:
    """Parse HTML error response
    :param html_text:
        HTML error message.
    :return:
        Parsed error message.
    """
    message = ''
    html = BeautifulSoup(markup=html_text, features="html.parser")
    if html.p:
        inner_html = BeautifulSoup(markup=html.p.text, features="html.parser")
        message = inner_html.text if inner_html.p is None else inner_html.p.text

    if "face_not_found" in message:
        message = "Could not find a face in the image."
    elif "multiple_faces" in message:
        message = "The image has more than one person."
    elif "quality_failed" in message:
        message = "The provided image does not have enough quality."
    else:
        message = "An error occurred. Please contact your systems administrator."
        print(f"ERROR: {html.text}")
    return message