Pecan adapter: Debug mode (which returns the exception tracebacks to the

client) can be enabled by the pecan application configuration.
This commit is contained in:
Christophe de Vienne 2013-04-16 15:42:23 +02:00
parent 0fd4d50279
commit cffcee226c
4 changed files with 35 additions and 1 deletions

View File

@ -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/

View File

@ -182,6 +182,23 @@ Pecan
`RestController <http://pecan.readthedocs.org/en/latest/rest.html>`_
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
~~~~~~~

View File

@ -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(

View File

@ -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: