diff --git a/wsme/api.py b/wsme/api.py index 4077f8c..7de462c 100644 --- a/wsme/api.py +++ b/wsme/api.py @@ -183,13 +183,18 @@ class Response(object): """ 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 self.obj = obj #: Store an optional 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): """Extract informations that can be sent to the client.""" diff --git a/wsmeext/cornice.py b/wsmeext/cornice.py index 0286374..0908189 100644 --- a/wsmeext/cornice.py +++ b/wsmeext/cornice.py @@ -23,6 +23,7 @@ import wsme from wsme.rest import json as restjson from wsme.rest import xml as restxml import wsme.runtime +import wsme.api import functools from wsme.rest.args import ( @@ -43,7 +44,13 @@ class WSMEJsonRenderer(object): else: response.status_code = 500 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):