diff --git a/supervisor/api/host.py b/supervisor/api/host.py index 6e3399420ae..7a6488f74ac 100644 --- a/supervisor/api/host.py +++ b/supervisor/api/host.py @@ -255,16 +255,21 @@ async def advanced_logs_handler( response.content_type = CONTENT_TYPE_TEXT headers_returned = False async for cursor, line in journal_logs_reader(resp, log_formatter): - if not headers_returned: - if cursor: - response.headers["X-First-Cursor"] = cursor - response.headers["X-Accel-Buffering"] = "no" - await response.prepare(request) - headers_returned = True - # When client closes the connection while reading busy logs, we - # sometimes get this exception. It should be safe to ignore it. - with suppress(ClientConnectionResetError): + try: + if not headers_returned: + if cursor: + response.headers["X-First-Cursor"] = cursor + response.headers["X-Accel-Buffering"] = "no" + await response.prepare(request) + headers_returned = True await response.write(line.encode("utf-8") + b"\n") + except ClientConnectionResetError as err: + # When client closes the connection while reading busy logs, we + # sometimes get this exception. It should be safe to ignore it. + _LOGGER.debug( + "ClientConnectionResetError raised when returning journal logs: %s", + err, + ) except ConnectionResetError as ex: raise APIError( "Connection reset when trying to fetch data from systemd-journald."