Skip to content

Commit 1e3522b

Browse files
committed
Default build_error() allows any serializable object as message
1 parent a4994eb commit 1e3522b

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

Diff for: restless/resources.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ def build_error(self, err):
208208
:returns: A response object
209209
"""
210210
data = {
211-
'error': six.text_type(err),
211+
'error': err.message,
212212
}
213213

214214
if self.is_debug():

Diff for: tests/test_dj.py

+8-2
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,10 @@ def update(self, pk):
8080
return
8181

8282
def create_detail(self):
83-
raise ValueError("This is a random & crazy exception.")
83+
raise ValueError({
84+
'code': 'random-crazy',
85+
'message': 'This is a random & crazy exception.',
86+
})
8487

8588
@skip_prepare
8689
def schema(self):
@@ -252,7 +255,10 @@ def test_handle_build_err(self):
252255
self.assertEqual(resp['Content-Type'], 'application/json')
253256
self.assertEqual(resp.status_code, 500)
254257
self.assertEqual(json.loads(resp.content.decode('utf-8')), {
255-
'error': 'This is a random & crazy exception.'
258+
'error': {
259+
'code': 'random-crazy',
260+
'message': 'This is a random & crazy exception.',
261+
}
256262
})
257263

258264
def test_object_does_not_exist(self):

0 commit comments

Comments
 (0)