utils: improve logging
This commit is contained in:
parent
c8c54f2e37
commit
086ec48823
|
@ -126,7 +126,7 @@ class Bot(irc.client.SimpleIRCClient, Logger):
|
|||
except KeyboardInterrupt:
|
||||
self.log_i("Caught keyboard interrupt.")
|
||||
except Exception as exc:
|
||||
self.log_c(f"Caught unhandled {type(exc)}: {exc}")
|
||||
self.log_c(f"Caught unhandled {type(exc).__name__}: {exc}")
|
||||
_, _, exc_traceback = sys.exc_info()
|
||||
for line in traceback.format_tb(exc_traceback):
|
||||
self.log_d(line.rstrip())
|
||||
|
|
|
@ -1,14 +1,20 @@
|
|||
import random
|
||||
from typing import Optional
|
||||
from typing import Callable, Optional
|
||||
|
||||
import requests
|
||||
|
||||
|
||||
def http_get(url: str) -> Optional[str]:
|
||||
response = requests.get(url)
|
||||
if response.status_code == 200:
|
||||
return response.text
|
||||
return None
|
||||
def http_get(url: str, log_e: Optional[Callable] = None) -> Optional[str]:
|
||||
"""Get the HTML as text from this URL.
|
||||
log_e is an optional error logging function."""
|
||||
try:
|
||||
response = requests.get(url)
|
||||
response.raise_for_status()
|
||||
except OSError as exc:
|
||||
if log_e:
|
||||
log_e(f"http_get error: {exc}")
|
||||
return None
|
||||
return response.text
|
||||
|
||||
|
||||
def proc(proba_percentage: int) -> bool:
|
||||
|
|
Loading…
Reference in a new issue