[pyramid] Fix 404 handling 3.24
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Wed, 09 Nov 2016 11:44:27 +0100
branch3.24
changeset 11812 4e0829ade86f
parent 11811 f09efeead7f9
child 11813 8a04a2cb5ba4
[pyramid] Fix 404 handling Avoid seeing a traceback in the UI by catching it before it reaches pyramid and restore usage of the '404' view. Closes #16159863
cubicweb/pyramid/bwcompat.py
cubicweb/pyramid/test/test_bw_request.py
--- a/cubicweb/pyramid/bwcompat.py	Wed Nov 09 11:42:33 2016 +0100
+++ b/cubicweb/pyramid/bwcompat.py	Wed Nov 09 11:44:27 2016 +0100
@@ -115,6 +115,11 @@
                 content = vreg['views'].main_template(req, 'login')
                 request.response.status_code = 403
                 request.response.body = content
+        except cubicweb.web.NotFound as ex:
+            view = vreg['views'].select('404', req)
+            content = vreg['views'].main_template(req, view=view)
+            request.response.status_code = ex.status
+            request.response.body = content
         finally:
             # XXX CubicWebPyramidRequest.headers_out should
             # access directly the pyramid response headers.
--- a/cubicweb/pyramid/test/test_bw_request.py	Wed Nov 09 11:42:33 2016 +0100
+++ b/cubicweb/pyramid/test/test_bw_request.py	Wed Nov 09 11:44:27 2016 +0100
@@ -97,6 +97,11 @@
                 content_type='application/x-www-form-urlencoded'))
         self.assertEqual(u"é", req.form['arg'])
 
+    def test_404(self):
+        r = self.webapp.get('/unexisting/', status=404)
+        self.assertNotIn('error occurred', r.text)
+        self.assertIn('resource does not exist', r.text)
+
 
 if __name__ == '__main__':
     from unittest import main