fix "UnboundLocalError"
This commit is contained in:
parent
308a590e8e
commit
574e91bb38
2 changed files with 7 additions and 10 deletions
|
|
@ -18,13 +18,12 @@ class CustomEncoder(json.JSONEncoder):
|
||||||
return list(obj)
|
return list(obj)
|
||||||
return json.JSONEncoder.default(self, obj)
|
return json.JSONEncoder.default(self, obj)
|
||||||
|
|
||||||
|
|
||||||
_EXCLUDE_FROM_LOGGING = ["base", "remove-bot", "remove-client", "restart-service"]
|
_EXCLUDE_FROM_LOGGING = ["base", "remove-bot", "remove-client", "restart-service"]
|
||||||
|
|
||||||
|
|
||||||
@web.middleware
|
@web.middleware
|
||||||
async def log_all_requests(
|
async def log_all_requests(request: Request, handler: Handler) -> StreamResponse:
|
||||||
request: Request, handler: Handler
|
|
||||||
) -> StreamResponse:
|
|
||||||
if request.match_info.route.name not in _EXCLUDE_FROM_LOGGING:
|
if request.match_info.route.name not in _EXCLUDE_FROM_LOGGING:
|
||||||
to_log = {
|
to_log = {
|
||||||
"request": {
|
"request": {
|
||||||
|
|
@ -55,10 +54,7 @@ async def log_all_requests(
|
||||||
"status": f"{response.status}",
|
"status": f"{response.status}",
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
if isinstance(response, Response) and response.body:
|
||||||
isinstance(response, Response)
|
|
||||||
and response.body
|
|
||||||
):
|
|
||||||
if response.content_type == "application/json":
|
if response.content_type == "application/json":
|
||||||
to_log["response"]["body"] = json.loads(response.text)
|
to_log["response"]["body"] = json.loads(response.text)
|
||||||
elif response.content_type.startswith("text"):
|
elif response.content_type.startswith("text"):
|
||||||
|
|
@ -71,7 +67,9 @@ async def log_all_requests(
|
||||||
raise
|
raise
|
||||||
|
|
||||||
except Exception:
|
except Exception:
|
||||||
_LOGGER.exception("An exception occurred in the logging middleware.", exc_info=True)
|
_LOGGER.exception(
|
||||||
|
"An exception occurred in the logging middleware.", exc_info=True
|
||||||
|
)
|
||||||
raise
|
raise
|
||||||
|
|
||||||
finally:
|
finally:
|
||||||
|
|
|
||||||
|
|
@ -178,7 +178,6 @@ class WebServer:
|
||||||
|
|
||||||
raise HTTPInternalServerError
|
raise HTTPInternalServerError
|
||||||
|
|
||||||
|
|
||||||
async def _restart_helper_bot(self) -> None:
|
async def _restart_helper_bot(self) -> None:
|
||||||
await bumper.mqtt_helperbot.disconnect()
|
await bumper.mqtt_helperbot.disconnect()
|
||||||
asyncio.create_task(bumper.mqtt_helperbot.start())
|
asyncio.create_task(bumper.mqtt_helperbot.start())
|
||||||
|
|
@ -374,7 +373,7 @@ class WebServer:
|
||||||
|
|
||||||
except asyncio.CancelledError:
|
except asyncio.CancelledError:
|
||||||
proxymodelog.exception(
|
proxymodelog.exception(
|
||||||
f"Request cancelled or timeout - {request.url} - {jdata}", exc_info=True
|
f"Request cancelled or timeout - {request.url}", exc_info=True
|
||||||
)
|
)
|
||||||
|
|
||||||
except Exception:
|
except Exception:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue