From 01c91bb89582bcd7b36c556ba80c5a1220f9a653 Mon Sep 17 00:00:00 2001 From: Lonami Exo Date: Mon, 25 Sep 2017 11:56:44 +0200 Subject: [PATCH] Report errors in the background not to interfer with users (#262) --- telethon/errors/__init__.py | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/telethon/errors/__init__.py b/telethon/errors/__init__.py index f2579f57..0d02545b 100644 --- a/telethon/errors/__init__.py +++ b/telethon/errors/__init__.py @@ -1,5 +1,6 @@ import urllib.request import re +from threading import Thread from .common import ( ReadCancelledError, InvalidParameterError, TypeNotFoundError, @@ -18,21 +19,28 @@ from .rpc_errors_401 import * from .rpc_errors_420 import * +def report_error(code, message, report_method): + try: + # Ensure it's signed + report_method = int.from_bytes( + report_method.to_bytes(4, 'big'), 'big', signed=True + ) + url = urllib.request.urlopen( + 'https://rpc.pwrtelegram.xyz?code={}&error={}&method={}' + .format(code, message, report_method) + ) + url.read() + url.close() + except: + "We really don't want to crash when just reporting an error" + + def rpc_message_to_error(code, message, report_method=None): if report_method is not None: - try: - # Ensure it's signed - report_method = int.from_bytes( - report_method.to_bytes(4, 'big'), 'big', signed=True - ) - url = urllib.request.urlopen( - 'https://rpc.pwrtelegram.xyz?code={}&error={}&method={}' - .format(code, message, report_method) - ) - url.read() - url.close() - except: - "We really don't want to crash when just reporting an error" + Thread( + target=report_method, + args=(code, message, report_method) + ).start() errors = { 303: rpc_errors_303_all,