[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
--- 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