Catch flask's NotFound error and return 404
This commit is contained in:
parent
5dd55dea55
commit
d4cd4003c3
@ -1,26 +1,32 @@
|
|||||||
from flask import render_template
|
from flask import render_template
|
||||||
|
import werkzeug.exceptions as werkzeug_exceptions
|
||||||
|
|
||||||
import atst.domain.exceptions as exceptions
|
import atst.domain.exceptions as exceptions
|
||||||
|
|
||||||
|
|
||||||
def make_error_pages(app):
|
def make_error_pages(app):
|
||||||
|
def log_error(e):
|
||||||
|
error_message = e.message if hasattr(e, "message") else str(e)
|
||||||
|
app.logger.error(error_message)
|
||||||
|
|
||||||
|
@app.errorhandler(werkzeug_exceptions.NotFound)
|
||||||
@app.errorhandler(exceptions.NotFoundError)
|
@app.errorhandler(exceptions.NotFoundError)
|
||||||
@app.errorhandler(exceptions.UnauthorizedError)
|
@app.errorhandler(exceptions.UnauthorizedError)
|
||||||
# pylint: disable=unused-variable
|
# pylint: disable=unused-variable
|
||||||
def not_found(e):
|
def not_found(e):
|
||||||
app.logger.error(e.message)
|
log_error(e)
|
||||||
return render_template("error.html", message="Not Found"), 404
|
return render_template("error.html", message="Not Found"), 404
|
||||||
|
|
||||||
@app.errorhandler(exceptions.UnauthenticatedError)
|
@app.errorhandler(exceptions.UnauthenticatedError)
|
||||||
# pylint: disable=unused-variable
|
# pylint: disable=unused-variable
|
||||||
def unauthorized(e):
|
def unauthorized(e):
|
||||||
app.logger.error(e.message)
|
log_error(e)
|
||||||
return render_template("error.html", message="Log in Failed"), 401
|
return render_template("error.html", message="Log in Failed"), 401
|
||||||
|
|
||||||
@app.errorhandler(Exception)
|
@app.errorhandler(Exception)
|
||||||
# pylint: disable=unused-variable
|
# pylint: disable=unused-variable
|
||||||
def exception(e):
|
def exception(e):
|
||||||
app.logger.error(e.message)
|
log_error(e)
|
||||||
return (
|
return (
|
||||||
render_template("error.html", message="An Unexpected Error Occurred"),
|
render_template("error.html", message="An Unexpected Error Occurred"),
|
||||||
500,
|
500,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user