Dash version: 2.16.1
Hi everyone,
Dash ignores my flask errorhandler when I run it with gunicorn. It seems that gunicorn is overwriting the flask errorhandler to print the exceptions to stderr. Here is my implementation:
from urllib.parse import urlparse
import dash
from flask import jsonify, request
app = dash.Dash(__name__)
server = app.server
@server.errorhandler(Exception)
def handle_exceptions(e):
return jsonify(error=str(e)), e.response.status_code
@server.after_request
def redirect_if_not_auth(response):
if request.path == "/_dash-update-component" and request.method == "POST":
if response.status_code == 403:
search = urlparse(request.referrer).path
href = "{}?{}={}".format("/login", "next", search)
return jsonify(
{
"multi": True,
"response": {"url-redirect": {"href": href}},
}
)
return response
def main():
app.run(debug=True)
if __name__ == "__main__":
main()
I run gunicorn as follows:
gunicorn myapp:server --bind localhost:8000 -chdir /path/to/project --workers 2
Is it possible to force gunicorn to use flask errorhandler?