[web/ajax] Always return a json dict with a 'reason' key in case of ajax errors
authorJulien Cristau <julien.cristau@logilab.fr>
Thu, 13 Mar 2014 17:03:15 +0100
changeset 9728 f79ce7b39ee9
parent 9727 33f6ad4c75a5
child 9730 8347e6d613c9
[web/ajax] Always return a json dict with a 'reason' key in case of ajax errors Sending sometimes a bare unicode string and sometimes a json-encoded dict seems like a bad idea.
web/application.py
--- a/web/application.py	Thu Mar 13 17:01:58 2014 +0100
+++ b/web/application.py	Thu Mar 13 17:03:15 2014 +0100
@@ -23,6 +23,7 @@
 from time import clock, time
 from contextlib import contextmanager
 from warnings import warn
+import json
 
 import httplib
 
@@ -584,7 +585,7 @@
         if req.status_out < 400:
             # don't overwrite it if it's already set
             req.status_out = status
-        json_dumper = getattr(ex, 'dumps', lambda : unicode(ex))
+        json_dumper = getattr(ex, 'dumps', lambda : json.dumps({'reason': unicode(ex)}))
         return json_dumper()
 
     # special case handling