Logging tidy-up, IDE inspection fixes

This commit is contained in:
Ian Renton
2026-08-15 07:42:38 +01:00
parent 9cd6d9c177
commit bff5b79f8f
40 changed files with 128 additions and 125 deletions
+2 -2
View File
@@ -232,8 +232,8 @@ class APISpotHandler(tornado.web.RequestHandler):
self.set_header("Cache-Control", "no-store")
self.set_header("Content-Type", "application/json")
except Exception as e:
logging.error("Exception when handling client request to add spot API: %s", e, exc_info=True)
except Exception:
logging.exception("Exception when handling client request to add spot API")
self.write(safe_json_dumps("Error - an internal server error occurred."))
self.set_status(500)
self.set_header("Cache-Control", "no-store")
+6 -17
View File
@@ -1,5 +1,4 @@
import copy
import inspect
import logging
from datetime import datetime
from typing import Any
@@ -53,28 +52,18 @@ class APIAlertsHandler(tornado.web.RequestHandler):
data = get_alert_list_with_filters(self._alerts, query_params)
if credentials:
data = self._enrich(data, credentials)
find_bad_values(data)
self.write(safe_json_dumps(data))
self.set_status(200)
except ValueError as e:
self.write(safe_json_dumps("Bad request - " + str(e)))
self.set_status(400)
except Exception as e:
logging.error("Exception when handling client request to alerts API: %s", e, exc_info=True)
except Exception:
logging.exception("Exception when handling client request to alerts API")
self.write(safe_json_dumps("Error - an internal server error occurred."))
self.set_status(500)
self.set_header("Cache-Control", "no-store")
self.set_header("Content-Type", "application/json")
def find_bad_values(obj, path="data"):
if isinstance(obj, dict):
for k, v in obj.items():
find_bad_values(v, f"{path}[{k!r}]")
elif isinstance(obj, (list, tuple)):
for i, v in enumerate(obj):
find_bad_values(v, f"{path}[{i}]")
elif inspect.isbuiltin(obj) or inspect.ismethod(obj) or inspect.isfunction(obj):
print(f"Found bad value at {path}: {obj!r}")
class APIAlertsStreamHandler(tornado_eventsource.handler.EventSourceHandler):
"""API request handler for /api/v2/alerts/stream"""
@@ -116,8 +105,8 @@ class APIAlertsStreamHandler(tornado_eventsource.handler.EventSourceHandler):
# argument.
self._sse_alert_broadcaster.register(self)
except Exception as e:
logging.warning("Exception when serving SSE socket: %s", e, exc_info=True)
except Exception:
logging.exception("Exception when serving SSE socket")
self.close()
def close(self):
@@ -135,8 +124,8 @@ class APIAlertsStreamHandler(tornado_eventsource.handler.EventSourceHandler):
alert = copy.deepcopy(alert)
alert.infer_missing(self._credentials)
self.write_message(msg=safe_json_dumps(alert))
except Exception as e:
logging.warning("Exception in SSE callback, connection will be closed: %s", e, exc_info=True)
except Exception:
logging.exception("Exception in SSE callback, connection will be closed")
self.close()
+2 -2
View File
@@ -59,7 +59,7 @@ class APIDxStatsHandler(tornado.web.RequestHandler):
self.set_header("Cache-Control", "no-store")
self.set_header("Content-Type", "application/json")
except Exception as e:
logging.error("Exception when handling client request to dx stats API: %s", e, exc_info=True)
except Exception:
logging.exception("Exception when handling client request to dx stats API")
self.write(safe_json_dumps("Error - an internal server error occurred."))
self.set_status(500)
+6 -6
View File
@@ -56,8 +56,8 @@ class APILookupCallHandler(tornado.web.RequestHandler):
self.write(safe_json_dumps("Error - call must be provided"))
self.set_status(422)
except Exception as e:
logging.error("Exception when handling client request to call lookup API: %s", e, exc_info=True)
except Exception:
logging.exception("Exception when handling client request to call lookup API")
self.write(safe_json_dumps("Error - an internal server error occurred."))
self.set_status(500)
@@ -108,8 +108,8 @@ class APILookupSIGRefHandler(tornado.web.RequestHandler):
self.write(safe_json_dumps("Error - sig and id must be provided"))
self.set_status(422)
except Exception as e:
logging.error("Exception when handling client request to sig ref lookup API: %s", e, exc_info=True)
except Exception:
logging.exception("Exception when handling client request to sig ref lookup API")
self.write(safe_json_dumps("Error - an internal server error occurred."))
self.set_status(500)
@@ -170,8 +170,8 @@ class APILookupGridHandler(tornado.web.RequestHandler):
self.write(safe_json_dumps("Error - grid must be provided"))
self.set_status(422)
except Exception as e:
logging.error("Exception when handling client request to grid ref lookup API: %s", e, exc_info=True)
except Exception:
logging.exception("Exception when handling client request to grid ref lookup API")
self.write(safe_json_dumps("Error - an internal server error occurred."))
self.set_status(500)
+2 -2
View File
@@ -82,7 +82,7 @@ class APIOptionsHandler(tornado.web.RequestHandler):
self.set_header("Cache-Control", "no-store")
self.set_header("Content-Type", "application/json")
except Exception as e:
logging.error("Exception when handling client request to options API: %s", e, exc_info=True)
except Exception:
logging.exception("Exception when handling client request to options API")
self.write(safe_json_dumps("Error - an internal server error occurred."))
self.set_status(500)
+2 -2
View File
@@ -36,7 +36,7 @@ class APISolarConditionsHandler(tornado.web.RequestHandler):
self.set_header("Cache-Control", "no-store")
self.set_header("Content-Type", "application/json")
except Exception as e:
logging.error("Exception when handling client request to solar conditions API: %s", e, exc_info=True)
except Exception:
logging.exception("Exception when handling client request to solar conditions API")
self.write(safe_json_dumps("Error - an internal server error occurred."))
self.set_status(500)
+6 -6
View File
@@ -57,8 +57,8 @@ class APISpotsHandler(tornado.web.RequestHandler):
except ValueError as e:
self.write(safe_json_dumps("Bad request - " + str(e)))
self.set_status(400)
except Exception as e:
logging.error("Excedption when handling client request to spots API: %s", e, exc_info=True)
except Exception:
logging.exception("Excedption when handling client request to spots API")
self.write(safe_json_dumps("Error - an internal server error occurred."))
self.set_status(500)
self.set_header("Cache-Control", "no-store")
@@ -107,8 +107,8 @@ class APISpotsStreamHandler(tornado_eventsource.handler.EventSourceHandler):
# argument.
self._sse_spot_broadcaster.register(self)
except Exception as e:
logging.warning("Exception when serving SSE socket: %s", e, exc_info=True)
except Exception:
logging.exception("Exception when serving SSE socket")
self.close()
def close(self):
@@ -127,8 +127,8 @@ class APISpotsStreamHandler(tornado_eventsource.handler.EventSourceHandler):
spot = copy.deepcopy(spot)
spot.infer_missing(self._credentials)
self.write_message(msg=safe_json_dumps(spot))
except Exception as e:
logging.warning("Exception in SSE callback, connection will be closed: %s", e, exc_info=True)
except Exception:
logging.exception("Exception in SSE callback, connection will be closed")
self.close()
+2 -2
View File
@@ -36,7 +36,7 @@ class APIStatusHandler(tornado.web.RequestHandler):
self.set_header("Cache-Control", "no-store")
self.set_header("Content-Type", "application/json")
except Exception as e:
logging.error("Exception when handling client request to status API: %s", e, exc_info=True)
except Exception:
logging.exception("Exception when handling client request to status API")
self.write(safe_json_dumps("Error - an internal server error occurred."))
self.set_status(500)
+2 -2
View File
@@ -125,8 +125,8 @@ class V1APISpotHandler(tornado.web.RequestHandler):
self.set_header("Cache-Control", "no-store")
self.set_header("Content-Type", "application/json")
except Exception as e:
logging.error("Exception when handling client request to add spot API: %s", e, exc_info=True)
except Exception:
logging.exception("Exception when handling client request to add spot API")
self.write(safe_json_dumps("Error - an internal server error occurred."))
self.set_status(500)
self.set_header("Cache-Control", "no-store")
+10 -7
View File
@@ -1,5 +1,7 @@
import tornado
from tornado.httpclient import AsyncHTTPClient
from tornado.httputil import HTTPHeaders
class V1RedirectHandler(tornado.web.RequestHandler):
"""Transparently proxies requests from the old API to the new one,
@@ -30,13 +32,14 @@ class V1RedirectHandler(tornado.web.RequestHandler):
raise tornado.web.HTTPError(502, reason=str(e))
self.set_status(response.code, response.reason)
for name, value in response.headers.get_all():
# Let Tornado recompute these for the outgoing response
if name.lower() not in ("content-length", "transfer-encoding", "connection"):
self.add_header(name, value)
if response.body:
self.write(response.body)
self.finish()
if isinstance(response.headers, HTTPHeaders):
for name, value in response.headers.get_all():
# Let Tornado recompute these for the outgoing response
if name.lower() not in ("content-length", "transfer-encoding", "connection"):
self.add_header(name, value)
if response.body:
self.write(response.body)
await self.finish()
async def get(self, path):
await self._proxy(path)