# HG changeset patch # User RĂ©mi Cardona # Date 1401982874 -7200 # Node ID 8227358aa983fab6717f7c26130f72a172cf6292 # Parent 5aa730bf445e7982dfd70aeddca676a1839f482f [web] Return useful error messages when exceptions arise in ajax controllers (closes #3932503) The call to super() in RemoteCallException passes 'reason' all the way to python's Exception.__init__() which is then stored in Exception.args. This way, CubicWebPublisher.ajax_error_handler() gets a useful error message when calling unicode(exc). The change to uilib is just to prepend the exception type name. Just a small improvement. diff -r 5aa730bf445e -r 8227358aa983 uilib.py --- a/uilib.py Wed Jul 23 19:42:42 2014 +0200 +++ b/uilib.py Thu Jun 05 17:41:14 2014 +0200 @@ -444,12 +444,14 @@ def exc_message(ex, encoding): try: - return unicode(ex) + excmsg = unicode(ex) except Exception: try: - return unicode(str(ex), encoding, 'replace') + excmsg = unicode(str(ex), encoding, 'replace') except Exception: - return unicode(repr(ex), encoding, 'replace') + excmsg = unicode(repr(ex), encoding, 'replace') + exctype = unicode(ex.__class__.__name__) + return u'%s: %s' % (exctype, excmsg) def rest_traceback(info, exception): diff -r 5aa730bf445e -r 8227358aa983 web/_exceptions.py --- a/web/_exceptions.py Wed Jul 23 19:42:42 2014 +0200 +++ b/web/_exceptions.py Thu Jun 05 17:41:14 2014 +0200 @@ -102,7 +102,7 @@ """raised when a json remote call fails """ def __init__(self, reason='', status=httplib.INTERNAL_SERVER_ERROR): - super(RemoteCallFailed, self).__init__(status=status) + super(RemoteCallFailed, self).__init__(reason, status=status) self.reason = reason def dumps(self):