Skip to content

Commit 960161f

Browse files
author
Joel Collins
committed
Improved Python exception handling
1 parent 66c5de0 commit 960161f

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

labthings/server/exceptions.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,21 @@ def std_handler(self, error):
2424

2525
status_code = error.code if isinstance(error, HTTPException) else 500
2626

27-
response = {"code": status_code, "message": escape(message)}
27+
response = {
28+
"code": status_code,
29+
"message": escape(message),
30+
"name": getattr(error, "__name__", None)
31+
or getattr(getattr(error, "__class__", None), "__name__", None)
32+
or None,
33+
}
2834
return jsonify(response), status_code
2935

3036
def init_app(self, app):
3137
self.app = app
3238
self.register(HTTPException)
3339
for code, v in default_exceptions.items():
3440
self.register(code)
41+
self.register(Exception)
3542

3643
def register(self, exception_or_code, handler=None):
3744
self.app.errorhandler(exception_or_code)(handler or self.std_handler)

0 commit comments

Comments
 (0)