[Kimchi-devel] [PATCH 1/3] refactor exception: Add a kimchi special error handler
Aline Manera
alinefm at linux.vnet.ibm.com
Fri Jan 31 18:20:51 UTC 2014
From: ShaoHe Feng <shaohef at linux.vnet.ibm.com>
Cherrpy support a custom error handling.
http://docs.cherrypy.org/stable/refman/_cperror.html#custom-error-handling
But the arguments of custom error handling are fixed.
They are (status, message, traceback, version)
http://docs.cherrypy.org/stable/refman/_cperror.html#anticipated-http-responses
But now in code we would raise an exception as:
raise KimchiError(<msg>, <params>)
We need to pass the message and the args
So we should not use the cherrpy custom error handling.
Overridden the HTTPError for kimchi needs.
Signed-off-by: ShaoHe Feng <shaohef at linux.vnet.ibm.com>
---
src/kimchi/template.py | 14 ++++++++++++++
1 file changed, 14 insertions(+)
diff --git a/src/kimchi/template.py b/src/kimchi/template.py
index 173e7c6..f14ee90 100644
--- a/src/kimchi/template.py
+++ b/src/kimchi/template.py
@@ -107,3 +107,17 @@ def render(resource, data):
raise
else:
raise cherrypy.HTTPError(406)
+
+class HTTPError(cherrypy.HTTPError):
+ def __init__(self, status=500, exception=None, message=None):
+ super(HTTPError, self).__init__(status, message)
+ self.exception = exception
+
+
+ def get_error_page(self, status, **kwargs):
+ data = {'message': self.exception.message}
+ if cherrypy.config.get("environment") != "production":
+ data['call_stack'] = cherrypy._cperror.format_exc()
+ res = render('error.html', data)
+
+ return res.encode("utf-8")
--
1.7.10.4
More information about the Kimchi-devel
mailing list