From b6f155a06ba8d0914138fe27f7f5fde60d42adcd Mon Sep 17 00:00:00 2001
From: Patrick Jentsch
Date: Fri, 10 Mar 2023 15:17:24 +0100
Subject: [PATCH] Fix error_handler
---
app/__init__.py | 6 +++---
app/errors/__init__.py | 7 ++++---
app/errors/handlers.py | 9 ++-------
3 files changed, 9 insertions(+), 13 deletions(-)
diff --git a/app/__init__.py b/app/__init__.py
index cc747a89..dcb58e47 100644
--- a/app/__init__.py
+++ b/app/__init__.py
@@ -54,6 +54,9 @@ def create_app(config: Config = Config) -> Flask:
scheduler.init_app(app)
socketio.init_app(app, message_queue=app.config['NOPAQUE_SOCKETIO_MESSAGE_QUEUE_URI']) # noqa
+ from .errors import init_app as init_error_handlers
+ init_error_handlers(app)
+
from .admin import bp as admin_blueprint
app.register_blueprint(admin_blueprint, url_prefix='/admin')
@@ -69,9 +72,6 @@ def create_app(config: Config = Config) -> Flask:
from .corpora import bp as corpora_blueprint
app.register_blueprint(corpora_blueprint, url_prefix='/corpora')
- from .errors import bp as errors_blueprint
- app.register_blueprint(errors_blueprint)
-
from .jobs import bp as jobs_blueprint
app.register_blueprint(jobs_blueprint, url_prefix='/jobs')
diff --git a/app/errors/__init__.py b/app/errors/__init__.py
index 0d79af48..1f0480b4 100644
--- a/app/errors/__init__.py
+++ b/app/errors/__init__.py
@@ -1,5 +1,6 @@
-from flask import Blueprint
+from werkzeug.exceptions import HTTPException
+from .handlers import generic_error_handler
-bp = Blueprint('errors', __name__)
-from . import handlers
+def init_app(app):
+ app.register_error_handler(HTTPException, generic_error_handler)
diff --git a/app/errors/handlers.py b/app/errors/handlers.py
index cc6c9268..5a6c413d 100644
--- a/app/errors/handlers.py
+++ b/app/errors/handlers.py
@@ -1,11 +1,6 @@
-from flask import render_template, request
-from werkzeug.exceptions import HTTPException
-from . import bp
+from flask import render_template
-@bp.errorhandler(HTTPException)
def generic_error_handler(e):
- if (request.accept_mimetypes.accept_json
- and not request.accept_mimetypes.accept_html):
- return {'errors': {'message': e.description}}, e.code
+ print('test')
return render_template('errors/error.html.j2', error=e), e.code