From 1d085d328b8002578b7b659c9ef77ff833e314a0 Mon Sep 17 00:00:00 2001 From: Jeremy Zhang Date: Mon, 19 Feb 2018 07:48:57 +0000 Subject: [PATCH] Move error handling to utils --- webapp/titanembeds/blueprints/gateway/gateway.py | 3 --- webapp/titanembeds/utils.py | 8 ++++++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/webapp/titanembeds/blueprints/gateway/gateway.py b/webapp/titanembeds/blueprints/gateway/gateway.py index fb9d383..815ce78 100644 --- a/webapp/titanembeds/blueprints/gateway/gateway.py +++ b/webapp/titanembeds/blueprints/gateway/gateway.py @@ -11,9 +11,6 @@ class Gateway(Namespace): db.session.commit() db.session.remove() - def on_error(self): - disconnect() - def on_connect(self): emit('hello') diff --git a/webapp/titanembeds/utils.py b/webapp/titanembeds/utils.py index d9b5f38..82c4595 100644 --- a/webapp/titanembeds/utils.py +++ b/webapp/titanembeds/utils.py @@ -2,7 +2,7 @@ from titanembeds.database import db, Guilds, UnauthenticatedUsers, Unauthenticat from titanembeds.constants import LANGUAGES from flask import request, session from flask_limiter import Limiter -from flask_socketio import SocketIO +from flask_socketio import SocketIO, disconnect from flask_babel import Babel from flask_redis import FlaskRedis from config import config @@ -324,4 +324,8 @@ def language_code_list(): rate_limiter = Limiter(key_func=get_client_ipaddr) # Default limit by ip address socketio = SocketIO() -babel = Babel() \ No newline at end of file +babel = Babel() + +@socketio.on_error_default # disconnect on all errors +def default_socketio_error_handler(e): + disconnect() \ No newline at end of file