Module: check_mk
Branch: master
Commit: 05334cbca6967433fb4edfac37c4b75c29d6a36f
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=05334cbca69674…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Tue May 23 10:16:38 2017 +0200
Improved error handling of API calls
Change-Id: Iaccc8572d73e65634d66c9b9b11e655d2bfdc803
---
web/htdocs/htmllib.py | 7 ++++++-
web/htdocs/modules.py | 9 ++++++---
2 files changed, 12 insertions(+), 4 deletions(-)
diff --git a/web/htdocs/htmllib.py b/web/htdocs/htmllib.py
index 528b4ba..e557732 100644
--- a/web/htdocs/htmllib.py
+++ b/web/htdocs/htmllib.py
@@ -1129,7 +1129,12 @@ class RequestHandler(object):
if exclude_vars == None:
exclude_vars = []
- request = json.loads(self.var("request", "{}"))
+ try:
+ json_request = self.var("request", "{}")
+ request = json.loads(json_request)
+ except json.JSONDecodeError, e:
+ raise MKUserError("request", _("Failed to parse request:
'%s': %s") %
+ (json_request, e))
for key, val in self.all_vars().items():
if key not in [ "request", "output_format" ] +
exclude_vars:
diff --git a/web/htdocs/modules.py b/web/htdocs/modules.py
index 6113883..3452780 100644
--- a/web/htdocs/modules.py
+++ b/web/htdocs/modules.py
@@ -102,15 +102,14 @@ g_all_modules_loaded = False
def load_all_plugins():
global g_all_modules_loaded
+ # Optimization: in case of the graph ajax call only check the metrics module. This
+ # improves the performance for these requests.
# TODO: CLEANUP: Move this to the pagehandlers if this concept works out.
if html.myfile == "ajax_graph" and g_all_modules_loaded:
only_modules = ["metrics"]
else:
only_modules = None
- g_all_modules_loaded = True
-
-
need_plugins_reload = local_web_plugins_have_changed()
for module in modules:
@@ -128,6 +127,10 @@ def load_all_plugins():
# have been loaded to update the pagehandlers
pagehandlers.update(pagetypes.page_handlers())
+ # Mark the modules as loaded after all plugins have been loaded. In case of
exceptions
+ # we want them to occur again on subsequent requests too.
+ g_all_modules_loaded = True
+
def get_handler(name, dflt=None):
return pagehandlers.get(name, dflt)