diff --git a/telegram_bot/shares/share_fetcher.py b/telegram_bot/shares/share_fetcher.py index f56c3fb..179a478 100644 --- a/telegram_bot/shares/share_fetcher.py +++ b/telegram_bot/shares/share_fetcher.py @@ -106,8 +106,16 @@ def get_share_information(str_search_for): return str_return def get_share_information_markdown(str_search_for): - search_result = investpy.search_quotes(text=str_search_for, products=['stocks'], - countries=['germany'], n_results=1) + + try: + search_result = investpy.search_quotes(text=str_search_for, products=['stocks'], + countries=['germany'], n_results=1) + + except RuntimeError as e: + return hf.make_markdown_proof(f"no shares found for \"{str_search_for}\"") # if no shares are found, make error message markdown proof and return + + except ConnectionError as e: + return hf.make_markdown_proof(f"connection not possible. Try again later.") # if no connection, make error message markdown proof and return str_return = f'*{hf.make_markdown_proof(search_result.name)}*\n_{hf.make_markdown_proof(search_result.symbol)}_\nworth: {hf.make_markdown_proof(get_share_price(str_search_for))}' return str_return