From 33308307a47bf9ffc6e553a273c3ab0dfea57aea Mon Sep 17 00:00:00 2001 From: SomberNight Date: Wed, 5 Jun 2019 19:40:33 +0200 Subject: [PATCH] bip70 payreq: do not show error messages in gui closes #5393 --- electrum/paymentrequest.py | 32 ++++++++++++++++++++++++++------ electrum/util.py | 1 + 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/electrum/paymentrequest.py b/electrum/paymentrequest.py index f12fd4026..fedcd1b3a 100644 --- a/electrum/paymentrequest.py +++ b/electrum/paymentrequest.py @@ -93,9 +93,19 @@ async def get_payment_request(url: str) -> 'PaymentRequest': data_len = len(data) if data is not None else None _logger.info(f'fetched payment request {url} {data_len}') except aiohttp.ClientError as e: - error = f"Error while contacting payment URL:\n{repr(e)}" - if isinstance(e, aiohttp.ClientResponseError) and e.status == 400 and resp_content: - error += "\n" + resp_content.decode("utf8") + error = f"Error while contacting payment URL: {url}.\nerror type: {type(e)}" + if isinstance(e, aiohttp.ClientResponseError): + error += f"\nGot HTTP status code {e.status}." + if resp_content: + try: + error_text_received = resp_content.decode("utf8") + except UnicodeDecodeError: + error_text_received = "(failed to decode error)" + else: + error_text_received = error_text_received[:400] + error_oneline = ' -- '.join(error.split('\n')) + _logger.info(f"{error_oneline} -- [DO NOT TRUST THIS MESSAGE] " + f"{repr(e)} text: {error_text_received}") data = None elif u.scheme == 'file': try: @@ -305,9 +315,19 @@ class PaymentRequest: print(f"PaymentACK message received: {paymntack.memo}") return True, paymntack.memo except aiohttp.ClientError as e: - error = f"Payment Message/PaymentACK Failed:\n{repr(e)}" - if isinstance(e, aiohttp.ClientResponseError) and e.status == 400 and resp_content: - error += "\n" + resp_content.decode("utf8") + error = f"Payment Message/PaymentACK Failed:\nerror type: {type(e)}" + if isinstance(e, aiohttp.ClientResponseError): + error += f"\nGot HTTP status code {e.status}." + if resp_content: + try: + error_text_received = resp_content.decode("utf8") + except UnicodeDecodeError: + error_text_received = "(failed to decode error)" + else: + error_text_received = error_text_received[:400] + error_oneline = ' -- '.join(error.split('\n')) + _logger.info(f"{error_oneline} -- [DO NOT TRUST THIS MESSAGE] " + f"{repr(e)} text: {error_text_received}") return False, error diff --git a/electrum/util.py b/electrum/util.py index 44ab5ec52..85aa46325 100644 --- a/electrum/util.py +++ b/electrum/util.py @@ -800,6 +800,7 @@ def parse_URI(uri: str, on_pr: Callable = None, *, loop=None) -> dict: sig = out.get('sig') name = out.get('name') if on_pr and (r or (name and sig)): + @log_exceptions async def get_payment_request(): from . import paymentrequest as pr if name and sig: