def http_error_page(error): # If we are catching some non-http exception it is an application error. if not isinstance(error, HTTPException): # Replace the specific error with this generic one. original = error # Attach additional information for reporting. error = InternalServerError() error.incident_number = random.randint(2**8, 2**16) error.original = original error.traceback = '\n'.join( traceback.format_exception(None, original, original.__traceback__)) # Log it, so if the recipient isn't an admin, the admins can later find # this in the logs. app.logger.error( "Incident %d; please submit the following code to\n%s\n%s", error.incident_number, app.config['REPOSITORY_ISSUES'], error.traceback) return flask.render_template('error.html', error=error), error.code