The Response object can now carry error details. Not sure about this though, it needs refinements
This commit is contained in:
parent
82d97971fc
commit
579772807e
@ -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."""
|
||||
|
@ -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):
|
||||
|
Loading…
x
Reference in New Issue
Block a user