from flask import render_template from werkzeug.exceptions import HTTPException from atlas_um.exceptions import AtlasException DESCRIPTIONS = { 401: "You are unauthorized to access this page.", 404: "The page you're looking for is not available.", 500: "Page is unavailable because of internal server error.", } def register_errors_handlers(app): app.register_error_handler(HTTPException, generic_error) def generic_error(error): if isinstance(error, AtlasException): description = error.description else: description = DESCRIPTIONS.get(error.code, error.description) return ( render_template( "error.html", code=error.code, description=description, ), error.code, )