Document the errors/ module

This commit is contained in:
Lonami Exo
2017-11-26 17:06:09 +01:00
parent a932fb6470
commit 71eb542626
3 changed files with 84 additions and 43 deletions

View File

@@ -1,3 +1,7 @@
"""
This module holds all the base and automatically generated errors that the
Telegram API has. See telethon_generator/errors.json for more.
"""
import urllib.request
import re
from threading import Thread
@@ -13,6 +17,13 @@ from .rpc_error_list import *
def report_error(code, message, report_method):
"""
Reports an RPC error to pwrtelegram.
:param code: the integer code of the error (like 400).
:param message: the message representing the error.
:param report_method: the constructor ID of the function that caused it.
"""
try:
# Ensure it's signed
report_method = int.from_bytes(
@@ -30,6 +41,14 @@ def report_error(code, message, report_method):
def rpc_message_to_error(code, message, report_method=None):
"""
Converts a Telegram's RPC Error to a Python error.
:param code: the integer code of the error (like 400).
:param message: the message representing the error.
:param report_method: if present, the ID of the method that caused it.
:return: the RPCError as a Python exception that represents this error.
"""
if report_method is not None:
Thread(
target=report_error,