The Response object can now carry error details. Not sure about this though, it needs refinements

This commit is contained in:
Christophe de Vienne 2013-06-21 00:22:23 +02:00
parent 82d97971fc
commit 579772807e
2 changed files with 14 additions and 2 deletions

View File

@ -183,13 +183,18 @@ class Response(object):
""" """
Object to hold the "response" from a view function Object to hold the "response" from a view function
""" """
def __init__(self, obj, status_code=None): def __init__(self, obj, status_code=None, error=None):
#: Store the result object from the view #: Store the result object from the view
self.obj = obj self.obj = obj
#: Store an optional status_code #: Store an optional status_code
self.status_code = status_code self.status_code = status_code
#: Return error details
#: Must be a dictionnary with the following keys: faultcode,
#: faultstring and an optional debuginfo
self.error = error
def format_exception(excinfo, debug=False): def format_exception(excinfo, debug=False):
"""Extract informations that can be sent to the client.""" """Extract informations that can be sent to the client."""

View File

@ -23,6 +23,7 @@ import wsme
from wsme.rest import json as restjson from wsme.rest import json as restjson
from wsme.rest import xml as restxml from wsme.rest import xml as restxml
import wsme.runtime import wsme.runtime
import wsme.api
import functools import functools
from wsme.rest.args import ( from wsme.rest.args import (
@ -43,7 +44,13 @@ class WSMEJsonRenderer(object):
else: else:
response.status_code = 500 response.status_code = 500
return restjson.encode_error(None, data) return restjson.encode_error(None, data)
return restjson.encode_result(data['result'], data['datatype']) obj = data['result']
if isinstance(obj, wsme.api.Response):
response.status_code = obj.status_code
if obj.error:
return restjson.encode_error(None, obj.error)
obj = obj.obj
return restjson.encode_result(obj, data['datatype'])
class WSMEXmlRenderer(object): class WSMEXmlRenderer(object):