Issue
I've spent quite a bit of time searching and I'm amazed I've not found an answer to this.
I've got basic @app.errorhandler(500) code in my flask app. As expected, I get a debugger when running with DEBUG on, and I get my custom error page when it's false. The next stage of my build though is serving the app from gunicorn in a docker container, and I'm just getting generic "Internal Server Error"s when I do that. I'm guessing gunicorn is handling the errors now instead of flask? But I can't for the life of me figure out how to ask it to let flask handle the errors (if that's even possible), or make it use custom error pages.
The final stage will be gunicorn in docker behind nginx, but I think I've found a config directive for nginx to make it let gunicorn handle the errors - I just need to get gunicorn to pass it down one level further so I can use my custom error page, and fire off notifications to relevant people with details regarding the error that occurred (which I suspect I'd lose if I did a custom error page at the gunicorn or nginx level). Help would be GREATLY appreciated.
Solution
I was able to fix it with the below handle. But I still can't properly explain it. In any case even though the original handling (@app.app_errorhandler(500)) worked fine with the dev flask server and not with gunicorn, I don't believe the problem is to be solved with gunicron. It needs to be solved within the code.
@app.app_errorhandler(Exception)
def handle_exception_error(err):
""" Defines how to handle Exception errors. """
logger.error(err)
return "INTERNAL_SERVER_ERROR", 500
Answered By - Dominik Sajovic
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.