From 07e0e15fdafb28843a92cd03681a07aa652008a9 Mon Sep 17 00:00:00 2001
From: Michael Merickel <michael@merickel.org>
Date: Tue, 23 May 2017 21:50:58 +0200
Subject: [PATCH] allow the execution policy to perform a last-ditch effort to render an exception view

---
 pyramid/router.py |   14 ++++++++++++--
 1 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/pyramid/router.py b/pyramid/router.py
index 8b7b7b6..7f3f9fb 100644
--- a/pyramid/router.py
+++ b/pyramid/router.py
@@ -1,3 +1,4 @@
+import sys
 from zope.interface import (
     implementer,
     providedBy,
@@ -24,6 +25,7 @@
     BeforeTraversal,
     )
 
+from pyramid.compat import reraise
 from pyramid.httpexceptions import HTTPNotFound
 from pyramid.request import Request
 from pyramid.view import _call_view
@@ -252,7 +254,15 @@
         response = self.execution_policy(environ, self)
         return response(environ, start_response)
 
-
 def default_execution_policy(environ, router):
     request = router.make_request(environ)
-    return router.invoke_request(request)
+    try:
+        return router.invoke_request(request)
+    except Exception:
+        exc_info = sys.exc_info()
+        try:
+            return request.invoke_exception_view(exc_info)
+        except HTTPNotFound:
+            reraise(*exc_info)
+        finally:
+            del exc_info  # avoid local ref cycle

--
Gitblit v1.9.3