Translate SSL/TLS and connection refused logs to ConnectionRefusedErrors

This commit is contained in:
rlaphoenix 2023-03-12 00:14:21 +00:00
parent 1ef7419966
commit 0530d24110
1 changed files with 10 additions and 1 deletions

View File

@ -140,9 +140,18 @@ async def aria2c(
log_buffer += f"{line.strip()}\n" log_buffer += f"{line.strip()}\n"
if log_buffer: if log_buffer:
log_buffer = log_buffer.rstrip()
refused_errors = (
"the target machine actively refused it",
"SSL/TLS handshake failure"
)
if segmented and any(x in log_buffer for x in refused_errors):
# likely too many connections
raise ConnectionRefusedError("Aria2 could not connect as the target machine actively refused it.")
# wrap to console width - padding - '[Aria2c]: ' # wrap to console width - padding - '[Aria2c]: '
log_buffer = "\n ".join(textwrap.wrap( log_buffer = "\n ".join(textwrap.wrap(
log_buffer.rstrip(), log_buffer,
width=console.width - 20, width=console.width - 20,
initial_indent="" initial_indent=""
)) ))