Files
spothole/webserver/handlers/api/status.py

39 lines
1.1 KiB
Python

import logging
from typing import Any
import tornado
from tornado import httputil
from tornado.web import Application
from core.utils import safe_json_dumps
logger = logging.getLogger(__name__)
class APIStatusHandler(tornado.web.RequestHandler):
"""API request handler for /api/v2/status"""
def __init__(
self,
application: "Application",
request: httputil.HTTPServerRequest,
**kwargs: Any,
):
self._status_data = None
super().__init__(application, request, **kwargs)
def initialize(self, status_data):
self._status_data = status_data
def get(self):
try:
self.write(safe_json_dumps(self._status_data))
self.set_status(200)
self.set_header("Cache-Control", "no-store")
self.set_header("Content-Type", "application/json")
except Exception:
logger.exception("Exception when handling client request to status API")
self.write(safe_json_dumps("Error - an internal server error occurred."))
self.set_status(500)