diff --git a/doc/changes.rst b/doc/changes.rst index fe5a45b..5a93d59 100644 --- a/doc/changes.rst +++ b/doc/changes.rst @@ -17,6 +17,9 @@ next * Add a special type 'HostRequest' that allow a function to ask for the host framework request object in its arguments. +* Pecan adapter: Debug mode (which returns the exception tracebacks to the + client) can be enabled by the pecan application configuration. + * New adapter: wsmeext.flask, for the Flask_ framework. .. _Flask: http://flask.pocoo.org/ diff --git a/doc/integrate.rst b/doc/integrate.rst index 335a455..7659a40 100644 --- a/doc/integrate.rst +++ b/doc/integrate.rst @@ -182,6 +182,23 @@ Pecan `RestController `_ instead of the expose decorator from Pecan. +Configuration +~~~~~~~~~~~~~ + +WSME can be configured through the application configation, by adding a 'wsme' +configuration entry in ``config.py``: + +.. code-block:: python + + wsme = { + 'debug': True + } + +Valid configuration variables are : + +- ``'debug'``: Wether or not to include exception tracebacks in the returned + server-side errors. + Example ~~~~~~~ diff --git a/tests/pecantest/test/tests/test_ws.py b/tests/pecantest/test/tests/test_ws.py index 621b672..506f0ef 100644 --- a/tests/pecantest/test/tests/test_ws.py +++ b/tests/pecantest/test/tests/test_ws.py @@ -1,5 +1,6 @@ from test.tests import FunctionalTest import json +import pecan class TestWS(FunctionalTest): @@ -92,6 +93,16 @@ class TestWS(FunctionalTest): a = json.loads(res.body) print a assert a['faultcode'] == 'Server' + assert a['debuginfo'] is None + + def test_serversideerror_with_debug(self): + pecan.set_config({'wsme': {'debug': True}}) + res = self.app.get('/divide_by_zero.json', expect_errors=True) + self.assertEqual(res.status, '500 Internal Server Error') + a = json.loads(res.body) + print a + assert a['faultcode'] == 'Server' + assert a['debuginfo'].startswith('Traceback (most recent call last):') def test_body_parameter(self): res = self.app.put( diff --git a/wsmeext/pecan.py b/wsmeext/pecan.py index 3fdb87f..42e1439 100644 --- a/wsmeext/pecan.py +++ b/wsmeext/pecan.py @@ -69,7 +69,10 @@ def wsexpose(*args, **kwargs): kwargs[funcdef.pass_request] = pecan.request result = f(self, *args, **kwargs) except: - data = wsme.api.format_exception(sys.exc_info()) + data = wsme.api.format_exception( + sys.exc_info(), + pecan.conf.get('wsme', {}).get('debug', False) + ) if data['faultcode'] == 'Client': pecan.response.status = 400 else: