def handle_page(self) -> None: """The page handler, called by the page registry""" response.set_content_type("application/json") try: action_response = self.page() resp = { "result_code": 0, "result": action_response, "severity": "success" } except MKMissingDataError as e: resp = {"result_code": 1, "result": str(e), "severity": "success"} except MKException as e: resp = {"result_code": 1, "result": str(e), "severity": "error"} except Exception as e: if active_config.debug: raise logger.exception("error calling AJAX page handler") handle_exception_as_gui_crash_report( plain_error=True, show_crash_link=getattr(g, "may_see_crash_reports", False), ) resp = {"result_code": 1, "result": str(e), "severity": "error"} response.set_data(json.dumps(resp))
def handle_unhandled_exception() -> Response: handle_exception_as_gui_crash_report( plain_error=plain_error(), fail_silently=fail_silently(), show_crash_link=getattr(g, "may_see_crash_reports", False), ) # This needs to be cleaned up. return response
def handle_page(self) -> None: try: response.set_content_type("application/cbor") response.set_data(cbor.encode(self.page())) except Exception as e: response.status_code = http_client.INTERNAL_SERVER_ERROR handle_exception_as_gui_crash_report( plain_error=True, show_crash_link=getattr(g, "may_see_crash_reports", False), ) response.set_data(str(e))
def _handle_exc(self, method) -> None: try: # FIXME: These methods write to the response themselves. This needs to be refactored. method() except MKException as e: response.status_code = http_client.BAD_REQUEST html.write_text(str(e)) except Exception as e: response.status_code = http_client.INTERNAL_SERVER_ERROR if active_config.debug: raise logger.exception("error calling AJAX page handler") handle_exception_as_gui_crash_report( plain_error=True, show_crash_link=getattr(g, "may_see_crash_reports", False), ) html.write_text(str(e))