mirror of
https://github.com/Rapptz/discord.py.git
synced 2025-07-11 04:17:58 +00:00
Add on_error event for doing something about uncaught exceptions.
This commit is contained in:
parent
568c2a773b
commit
4aecd5f7b5
@ -38,7 +38,7 @@ import json, re, time, copy
|
|||||||
from collections import deque
|
from collections import deque
|
||||||
from threading import Timer
|
from threading import Timer
|
||||||
from ws4py.client.threadedclient import WebSocketClient
|
from ws4py.client.threadedclient import WebSocketClient
|
||||||
from sys import platform as sys_platform
|
import sys
|
||||||
|
|
||||||
def _null_event(*args, **kwargs):
|
def _null_event(*args, **kwargs):
|
||||||
pass
|
pass
|
||||||
@ -197,7 +197,8 @@ class Client(object):
|
|||||||
try:
|
try:
|
||||||
self.events[event_name](*args, **kwargs)
|
self.events[event_name](*args, **kwargs)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
pass
|
self.events['error'](event_name, *sys.exc_info())
|
||||||
|
|
||||||
|
|
||||||
def _received_message(self, msg):
|
def _received_message(self, msg):
|
||||||
response = json.loads(str(msg))
|
response = json.loads(str(msg))
|
||||||
@ -511,7 +512,7 @@ class Client(object):
|
|||||||
'd': {
|
'd': {
|
||||||
'token': self.token,
|
'token': self.token,
|
||||||
'properties': {
|
'properties': {
|
||||||
'$os': sys_platform,
|
'$os': sys.platform,
|
||||||
'$browser': 'discord.py',
|
'$browser': 'discord.py',
|
||||||
'$device': 'discord.py',
|
'$device': 'discord.py',
|
||||||
'$referrer': '',
|
'$referrer': '',
|
||||||
|
13
docs/api.rst
13
docs/api.rst
@ -30,6 +30,19 @@ All events are 'sandboxed', in that if an exception is thrown while the event is
|
|||||||
|
|
||||||
Called when the client disconnects for whatever reason. Be it error or manually.
|
Called when the client disconnects for whatever reason. Be it error or manually.
|
||||||
|
|
||||||
|
.. function:: on_error(event, type, value, traceback)
|
||||||
|
|
||||||
|
Usually when an event throws an uncaught exception, it is swallowed. If you want to handle
|
||||||
|
the uncaught exceptions for whatever reason, this event is called. If an exception is thrown
|
||||||
|
on this event then it propagates (i.e. it is not swallowed silently).
|
||||||
|
|
||||||
|
The parameters for this event are retrieved through the use of ``sys.exc_info()``.
|
||||||
|
|
||||||
|
:param event: The event name that had the uncaught exception.
|
||||||
|
:param type: The type of exception that was swallowed.
|
||||||
|
:param value: The actual exception that was swallowed.
|
||||||
|
:param traceback: The traceback object representing the traceback of the exception swallowed.
|
||||||
|
|
||||||
.. function:: on_message(message)
|
.. function:: on_message(message)
|
||||||
|
|
||||||
Called when a message is created and sent to a server.
|
Called when a message is created and sent to a server.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user