From 00a502f22c416ff5b78f7e308af0cf1bffad4645 Mon Sep 17 00:00:00 2001 From: Sumesh Punakkal Kariyil Date: Sun, 21 Feb 2021 14:24:54 -0800 Subject: [PATCH 1/2] Handling Jose parse errors --- api/qsystem.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/api/qsystem.py b/api/qsystem.py index 8f08594b1..d72cf19da 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 @@ -360,6 +361,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): From a02e4083a7a91eb6c426b97f71aaac3128586d2e Mon Sep 17 00:00:00 2001 From: Sumesh Punakkal Kariyil Date: Sun, 21 Feb 2021 20:08:55 -0800 Subject: [PATCH 2/2] Adding a handler for socket error. --- api/app/resources/theq/websocket.py | 7 +++++++ 1 file changed, 7 insertions(+) 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)