== How to fix it in Flask

Implement proper error handling by reporting customized error messages that do not contain a detailed stack trace. Log the exception stack trace if needed.

=== Code examples

==== Noncompliant code example

[source,python,diff-id=1,diff-type=noncompliant]
----
@app.errorhandler(500)
def internal_server_error(error):
    error_message = traceback.format_stack()
    return render_template('error.html', error_message=error_message), 500
----

==== Compliant solution

[source,python,diff-id=1,diff-type=compliant]
----
@app.errorhandler(500)
def internal_server_error(error):
    error_message = "Internal Server Error"
    logging.exception()
    return render_template('error.html', error_message=error_message), 500
----
