mirror of
https://git.ianrenton.com/ian/spothole.git
synced 2026-08-15 08:57:31 +00:00
Oops, "type" was a bad choice of field name
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import copy
|
||||
import inspect
|
||||
import logging
|
||||
from datetime import datetime
|
||||
from typing import Any
|
||||
@@ -52,6 +53,7 @@ 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:
|
||||
@@ -64,6 +66,15 @@ class APIAlertsHandler(tornado.web.RequestHandler):
|
||||
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"""
|
||||
|
||||
Reference in New Issue
Block a user