We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
I have a Flask application with a global exception handler defined as follows:
@app.errorhandler(Exception) def handle_generic_exception(error): traceback.print_exc() return Response( status=ExceptionType.GENERIC_EXCEPTION.http_status, mimetype='application/json', response=json.dumps({ 'error': ExceptionType.GENERIC_EXCEPTION.message, }), )
Additionally, I have a simple route that raises an exception:
@app.route("/") def hello_world(): raise Exception('Not Work') return json.dumps({"message": "Hello, World!"})
When running the application locally using:
app.run(host="0.0.0.0", port=8000, debug=settings.IS_LOCAL)
the exception handler works correctly, and a JSON response with the defined error message is returned.
However, when running the application via Gunicorn:
gunicorn -w 4 grade_wiz.grade_wiz:app --timeout 3600 --keep-alive 5 --log-level info --bind=0.0.0.0:8000
the @app.errorhandler(Exception) does not catch the exception, and a standard HTTP 500 response is returned instead.
@app.errorhandler(Exception)
How can I properly configure exception handling in Flask so the handler works correctly when running via Gunicorn?
Any advice or guidance on possible solutions would be greatly appreciated.
The text was updated successfully, but these errors were encountered:
No branches or pull requests
Issue with Flask Exception Handler When Running via Gunicorn
Environment
Problem Description
I have a Flask application with a global exception handler defined as follows:
Additionally, I have a simple route that raises an exception:
Expected Behavior
When running the application locally using:
the exception handler works correctly, and a JSON response with the defined error message is returned.
Issue
However, when running the application via Gunicorn:
the
@app.errorhandler(Exception)
does not catch the exception, and a standard HTTP 500 response is returned instead.Requested Help
How can I properly configure exception handling in Flask so the handler works correctly when running via Gunicorn?
Any advice or guidance on possible solutions would be greatly appreciated.
The text was updated successfully, but these errors were encountered: