hfaran / Tornado-JSON

A simple JSON API framework based on Tornado
http://tornado-json.readthedocs.org/
MIT License
273 stars 60 forks source link

Swap data and message fields for unhandled exceptions #77

Closed lockie closed 8 years ago

lockie commented 9 years ago

See #76

hfaran commented 9 years ago

Ah, I see.

The only issue is, this kind of flies in the face of JSend. In this case, if debug is turned off, message is in fact None, which makes it useless and not "A meaningful, end-user-readable (or at the least log-worthy) message, explaining what went wrong." as described in the JSend spec.

I would consider doing something like this though:

-                message=self._reason,
-                data=get_exc_message(exception) if self.settings.get("debug")
-                else None
+                message="{}{}".format(self._reason, "; {}".format(get_exc_message(exception)) if self.settings.get("debug") else "")

This way the whole error is contained in message, which makes a lot of sense to me. On the client side, it's simply a matter of checking message if the status is error which really shouldn't be that hard to do.

lockie commented 9 years ago

This way the whole error is contained in message, which makes a lot of sense to me.

You're right, it does to me to. But then again, there's issue with expected exceptions :) I'll describe it in #76.

lockie commented 9 years ago

Oops, broke it. Sorry.