changeset 937:00236973e138

server (pages): an HTTP internal error is raised if an error is uncatched during page workflow
author Goffi <goffi@goffi.org>
date Thu, 27 Apr 2017 01:13:50 +0200
parents 78692d47340d
children 9be057e23ce6
files src/server/server.py
diffstat 1 files changed, 11 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/server/server.py	Thu Apr 27 01:12:57 2017 +0200
+++ b/src/server/server.py	Thu Apr 27 01:13:50 2017 +0200
@@ -1482,6 +1482,7 @@
 
     @classmethod
     def importPages(cls, host, parent=None, path=None):
+        """Recursively import Libervia pages"""
         if path is None:
             path = []
         if parent is None:
@@ -1642,6 +1643,7 @@
         raise failure.Failure(exceptions.CancelError(u'error page is used'))
 
     def writeData(self, data, request):
+        """write data to transport and finish the request"""
         if data is None:
             self.pageError(request)
         request.write(data.encode('utf-8'))
@@ -1681,6 +1683,13 @@
         """don't raise error on CancelError"""
         failure_.trap(exceptions.CancelError)
 
+    def _internalError(self, failure_, request):
+        """called if an error is not catched"""
+        log.error(_(u"Uncatched error for HTTP request on {url}: {msg}").format(
+            url = request.URLPath(),
+            msg = failure_))
+        self.pageError(request, C.HTTP_INTERNAL_ERROR)
+
     def _on_data_post(self, dummy, request):
         return defer.maybeDeferred(self.on_data_post, self, request)
 
@@ -1750,6 +1759,7 @@
         return data
 
     def renderPage(self, request, skip_parse_url=False):
+        """Main method to handle the workflow of a LiberviaPage"""
         # template_data are the variables passed to template
         if not hasattr(request, 'template_data'):
             request.template_data = {}
@@ -1796,6 +1806,7 @@
 
         d.addCallback(self.writeData, request)
         d.addErrback(self._renderEb, request)
+        d.addErrback(self._internalError, request)
         d.callback(self)
         return server.NOT_DONE_YET