-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Log exceptions and responses in Flask routes. #31
Conversation
@@ -46,6 +47,17 @@ | |||
else: | |||
app = Flask(__name__, static_folder="../client/build") | |||
|
|||
|
|||
@app.errorhandler(Exception) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Excellent! This avoids us explicitly logging every error in route handlers.
Can we also use add a @app.after_request
handler to automatically log the responses? (We might need some special handling to avoid logging sensitive information like a route that parse VNC passwords, but we can think more about those in anther PR. )
Please also help adding the sys.excepthook and ExceptionThread utilities we discussed offline (documented in some internal notes) to handle uncaught exceptions outside of Flask route handlers. Previously I believe @li-ruihao was assigned to integrate those, but we didn't end up submitting those in #28 . Let's coordinate and see if the changes are suitable to be made in this PR or another one. |
|
||
@app.after_request | ||
def handle_after_request(response: Flask.response_class): | ||
if response.content_type == 'application/json': |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some routes that return json as a response do not necessarily mark the content_type as "application/json". e.g., in route /sftp/ls",
iCtrl/application/routes/sftp.py
Line 51 in 441dad7
return json.dumps(result) |
We shall replace all json.dumps()
with jsonify()
from the Flask library.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's postpone that to another PR. We will merge this PR first to unblock others.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
No description provided.