import requests


def error_parser(resp_err: requests.Response, api: str = 'graph') -> str:
    """
    Parses Microsoft API error message from Requests response
    :param resp_err: response with error
    :param api: API to query (graph/bot)
    :return: string of error
    """
    try:
        response: dict = resp_err.json()
        if api == 'graph':
            error: dict = response.get('error', {})
            err_str: str = f"{error.get('code', '')}: {error.get('message', '')}"
            if err_str:
                return err_str
        elif api == 'bot':
            error_description: str = response.get('error_description', '')
            if error_description:
                return error_description
        # If no error message
        raise ValueError()
    except ValueError:
        return resp_err.text