Mercurial > piecrust2
changeset 1082:8d5b8a3dca02
serve: Show debug info, report errors when debug info isn't available.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Thu, 15 Feb 2018 21:17:01 -0800 |
parents | d4e0c53aa6e8 |
children | 35937f8a52b1 |
files | piecrust/resources/server/piecrust-debug-info.js piecrust/serving/middlewares.py |
diffstat | 2 files changed, 10 insertions(+), 9 deletions(-) [+] |
line wrap: on
line diff
--- a/piecrust/resources/server/piecrust-debug-info.js Thu Feb 15 21:16:10 2018 -0800 +++ b/piecrust/resources/server/piecrust-debug-info.js Thu Feb 15 21:17:01 2018 -0800 @@ -284,13 +284,11 @@ xmlHttp.onreadystatechange = function() { if (xmlHttp.readyState == XMLHttpRequest.DONE) { var info = document.querySelector('.piecrust-debug-info'); - if(xmlHttp.status == 200) { + if(xmlHttp.status < 500) { info.innerHTML = xmlHttp.responseText; } - else if(xmlHttp.status == 400) { - info.innerHTML = "Error fetching debug info."; - } else { + console.log(xmlHttp); info.innerHTML = "Unknown error."; } }
--- a/piecrust/serving/middlewares.py Thu Feb 15 21:16:10 2018 -0800 +++ b/piecrust/serving/middlewares.py Thu Feb 15 21:17:01 2018 -0800 @@ -1,5 +1,5 @@ import os.path -from werkzeug.exceptions import NotFound, Forbidden +from werkzeug.exceptions import HTTPException, NotFound, Forbidden from werkzeug.wrappers import Request, Response from werkzeug.wsgi import ClosingIterator from piecrust import RESOURCES_DIR, CACHE_DIR @@ -71,14 +71,17 @@ rel_req_path = request.path[len(debug_mount):] handler = self._handlers.get(rel_req_path) if handler is not None: - return handler(request, start_response) + try: + return handler(request, start_response) + except HTTPException as ex: + return ex(environ, start_response) return self.app(environ, start_response) def _getDebugInfo(self, request, start_response): app = get_app_for_server(self.appfactory) - if not app.config.get('site/enable_debug_info'): - return Forbidden() + if not app.config.get('site/enable_debug_info', True): + raise Forbidden("PieCrust debug info isn't enabled.") found = False page_path = request.args.get('page') @@ -88,7 +91,7 @@ except (RouteNotFoundError, PageNotFoundError): pass if not found: - return NotFound("No such page: %s" % page_path) + raise NotFound("No such page: %s" % page_path) ctx = DataBuildingContext(req_page.page, sub_num=req_page.sub_num)