Forums

Flask: Custom Page for when "Something went wrong :-(: error

Occasionally I change the mysql database being used for my Flask web app. This produces an Error running WSGI application 2020-07-10 14:58:37,111: mysql.connector.errors.ProgrammingError: 1064 (42000): error.... Once the database changes are committed the web app works fine again.

How can I change it so that the Error running WSGI application error doesn't produce the python anywhere "Something went wrong:-(" -but to a custom error page, where I can tell the web app user to wait a minute then refresh the page. I.e. there is nothing wrong with the web app, I am just doing some temp fiddling in the background.

Here are the current error handlers in my app.py, but this isn't stopping the something went wrong :-( page. Thanks for your help

@app.errorhandler(403) # Forbidden
def error1(error):
   return render_template('403.html'), 403

@app.errorhandler(404) # not found
def error2(error):
   return render_template('404.html'), 404

@app.errorhandler(500) # Server error
def error3(error):
   return render_template('500.html'), 500

The failure is preventing your web app from starting, so those error handlers will have no effect. If you want them to work, you will need to put the code that is failing somewhere so it is not run at import time in your web app. Then your web app would be able to start and, even though individual pages would error, the web app would be running so the error handlers would be available.