cobbler/cobbler-catch-cheetah-excep...

69 lines
2.5 KiB
Diff

diff -ur cobbler.orig/scripts/services.py cobbler/scripts/services.py
--- cobbler.orig/scripts/services.py 2012-11-09 17:31:33.000000000 +0100
+++ cobbler/scripts/services.py 2012-11-09 17:31:51.000000000 +0100
@@ -86,7 +86,12 @@
mode = form.get('op','index')
func = getattr( cw, mode )
- content = func( **form )
+ try:
+ content = func( **form )
+ except xmlrpclib.Fault, (err):
+ req.status = apache.HTTP_INTERNAL_SERVER_ERROR
+ req.write(err.faultString)
+ return apache.OK
# apache.log_error("%s:%s ... %s" % (my_user, my_uri, str(form)))
req.content_type = "text/plain;charset=utf-8"
diff -ur cobbler.orig/scripts/services.wsgi cobbler/scripts/services.wsgi
--- cobbler.orig/scripts/services.wsgi 2012-11-09 17:31:33.000000000 +0100
+++ cobbler/scripts/services.wsgi 2012-11-09 17:31:58.000000000 +0100
@@ -21,6 +21,7 @@
"""
import yaml
import os
+import xmlrpclib
from cobbler.services import CobblerSvc
import cobbler.utils as utils
@@ -75,22 +76,26 @@
# Execute corresponding operation on the CobblerSvc object:
func = getattr( cw, mode )
- content = func( **form )
+ try:
+ content = func( **form )
- content = unicode(content).encode('utf-8')
- status = '200 OK'
+ content = unicode(content).encode('utf-8')
+ status = '200 OK'
+
+ if content.find("# *** ERROR ***") != -1:
+ status = '500 SERVER ERROR'
+ print("possible cheetah template error")
- if content.find("# *** ERROR ***") != -1:
+ # TODO: Not sure these strings are the right ones to look for...
+ elif content.find("# profile not found") != -1 or \
+ content.find("# system not found") != -1 or \
+ content.find("# object not found") != -1:
+ print("content not found: %s" % my_uri)
+ status = "404 NOT FOUND"
+ except xmlrpclib.Fault, (err):
status = '500 SERVER ERROR'
- print("possible cheetah template error")
-
- # TODO: Not sure these strings are the right ones to look for...
- elif content.find("# profile not found") != -1 or \
- content.find("# system not found") != -1 or \
- content.find("# object not found") != -1:
- print("content not found: %s" % my_uri)
- status = "404 NOT FOUND"
-
+ content = err.faultString
+
# req.content_type = "text/plain;charset=utf-8"
response_headers = [('Content-type', 'text/plain;charset=utf-8'),
('Content-Length', str(len(content)))]