from flask import Flask
from config import *
from flask_login import LoginManager
from flask import render_template

app = Flask(__name__)
app.debug = DEBUG
app.secret_key = SECRET_KEY

login_manager = LoginManager()
login_manager.init_app(app)

@login_manager.unauthorized_handler
def unauthorized():
    # do stuff
    return render_template('unauthorized.html')

@@ -183,138 +183,54 @@
 EY%0A%0A
-login_manager = LoginManager()%0Alogin_manager.init_app(app)%0A%0A@login_manager.unauthorized_handler%0Adef unauthorized():%0A    # do stuff
+%0A@app.errorhandler(401)%0Adef custom_401(error):
 %0A   

Correct 401 error handling