Skip to content

Commit 381714e

Browse files
authored
Merge pull request CloudBotIRC#126 from linuxdaemon/gonzobot+requests-errors
Add more data for requests errors to chan_log
2 parents 9bfdbca + b70412b commit 381714e

1 file changed

Lines changed: 27 additions & 17 deletions

File tree

plugins/core/chan_log.py

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
11
import traceback
22

3-
from requests import HTTPError
3+
from requests.exceptions import RequestException
44

55
from cloudbot import hook
66
from cloudbot.util import web
77

88

9+
def _dump_attrs(obj):
10+
for name in dir(obj):
11+
if not name.startswith('_'):
12+
yield name, getattr(obj, name, None)
13+
14+
915
@hook.post_hook
10-
def on_hook_end(error, launched_hook, launched_event, conn, admin_log):
16+
def on_hook_end(error, launched_hook, launched_event, admin_log):
1117
should_broadcast = True
1218
if error is not None:
1319
admin_log(
@@ -20,21 +26,25 @@ def on_hook_end(error, launched_hook, launched_event, conn, admin_log):
2026
url = web.paste('\n'.join(lines))
2127
admin_log("Traceback: " + url, should_broadcast)
2228

23-
event_data = launched_event.__dict__.items()
24-
lines = ["{} = {}".format(k, v) for k, v in event_data]
25-
26-
if isinstance(error, HTTPError) and error.response is not None:
27-
response = error.response
28-
lines.append("")
29-
lines.append("Request Info:")
30-
data = (
31-
("URL", response.url),
32-
("Status", response.status_code),
33-
("Raw Content", response.content),
34-
)
35-
lines.extend(
36-
"{} = {}".format(k, v) for k, v in data
37-
)
29+
lines = ["{} = {}".format(k, v) for k, v in _dump_attrs(launched_event)]
30+
exc_type, exc, exc_tb = error
31+
32+
lines.append("")
33+
lines.append("Error data:")
34+
lines.extend("{} = {}".format(k, v) for k, v in _dump_attrs(exc))
35+
36+
if isinstance(exc, RequestException):
37+
if exc.request is not None:
38+
req = exc.request
39+
lines.append("")
40+
lines.append("Request Info:")
41+
lines.extend("{} = {}".format(k, v) for k, v in _dump_attrs(req))
42+
43+
if exc.response is not None:
44+
response = exc.response
45+
lines.append("")
46+
lines.append("Response Info:")
47+
lines.extend("{} = {}".format(k, v) for k, v in _dump_attrs(response))
3848

3949
url = web.paste('\n'.join(lines))
4050
admin_log("Event: " + url, should_broadcast)

0 commit comments

Comments
 (0)