diff --git a/api/app/resources/theq/websocket.py b/api/app/resources/theq/websocket.py index 26e39bd9e..e40404d15 100644 --- a/api/app/resources/theq/websocket.py +++ b/api/app/resources/theq/websocket.py @@ -18,6 +18,7 @@ from app.auth.auth import jwt from app.models.theq import CSR, Office from qsystem import socketio, my_print +from flask_jwt_oidc.exceptions import AuthError @socketio.on('joinRoom') @@ -72,3 +73,9 @@ def clear_csr_user_id(csr_id): @socketio.on('sync_offices_cache') def sync_offices_cache(): Office.clear_offices_cache() + + +@socketio.on_error() +def error_handler(e): + # Passing the execution as it would be an auth error with invalid token. + print('Socket error ', e) diff --git a/api/qsystem.py b/api/qsystem.py index 5b51fdd05..6a404ff80 100644 --- a/api/qsystem.py +++ b/api/qsystem.py @@ -20,6 +20,7 @@ from sqlalchemy.exc import SQLAlchemyError from app.exceptions import AuthError from flask_jwt_oidc.exceptions import AuthError as JwtAuthError +from jose.exceptions import JOSEError from sqlalchemy import event from sqlalchemy.engine import Engine @@ -362,6 +363,12 @@ def handle_jwt_auth_error(error): return error.error, error.status_code +@application.errorhandler(JOSEError) +@api.errorhandler(JOSEError) +def handle_jose_jwt_error(error): + return {}, 401 + + @event.listens_for(Engine, "before_cursor_execute") def before_cursor_execute(conn, cursor, statement, parameters, context, executemany):