Skip to content

Commit

Permalink
bip70 payreq: do not show error messages in gui
Browse files Browse the repository at this point in the history
closes #5393
  • Loading branch information
SomberNight committed Jun 5, 2019
1 parent 0553ab7 commit 3330830
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 6 deletions.
32 changes: 26 additions & 6 deletions electrum/paymentrequest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -305,9 +315,19 @@ async def send_payment_and_receive_paymentack(self, raw_tx, refund_addr):
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


Expand Down
1 change: 1 addition & 0 deletions electrum/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 3330830

Please sign in to comment.