diff --git a/app/corpora/pj_events.py b/app/corpora/pj_events.py index 0d9feb1b..836b4d36 100644 --- a/app/corpora/pj_events.py +++ b/app/corpora/pj_events.py @@ -1,7 +1,8 @@ from flask import current_app, request from flask_login import current_user +from socket import gaierror from . import cqi -from .. import db, socketio +from .. import db, logger, socketio from ..decorators import socketio_login_required from ..events import connected_sessions from ..models import Corpus, User @@ -93,7 +94,7 @@ def pj_corpus_analysis_session_handler(app, corpus_id, user_id, session_id): socketio.sleep(3) client = cqi.CQiClient('corpus_{}_analysis'.format(corpus_id)) try: - client.connect() + connect_status = client.connect() except cqi.errors.CQiException as e: response = {'code': 500, 'desc': None, 'msg': 'Internal Server Error', @@ -101,12 +102,18 @@ def pj_corpus_analysis_session_handler(app, corpus_id, user_id, session_id): 'msg': e.name}} socketio.emit('pj_corpus_analysis_init', response, room=session_id) return + except gaierror: + response = {'code': 500, 'desc': None, + 'msg': 'Internal Server Error'} + socketio.emit('pj_corpus_analysis_init', response, room=session_id) + return pj_corpus_analysis_clients[session_id] = client if corpus_id not in pj_corpus_analysis_sessions: pj_corpus_analysis_sessions[corpus_id] = [session_id] else: pj_corpus_analysis_sessions[corpus_id].append(session_id) - response = {'code': 200, 'desc': None, 'msg': 'OK'} + response = {'code': 200, 'desc': None, 'msg': 'OK', + 'payload': {**connect_status}} socketio.emit('pj_corpus_analysis_init', response, room=session_id) ''' Observe analysis session ''' while session_id in connected_sessions: diff --git a/app/static/js/nopaque.CorpusAnalysisClient.js b/app/static/js/nopaque.CorpusAnalysisClient.js index abde67b4..1c99c0f7 100644 --- a/app/static/js/nopaque.CorpusAnalysisClient.js +++ b/app/static/js/nopaque.CorpusAnalysisClient.js @@ -6,12 +6,14 @@ class CorpusAnalysisClient { this.socket = socket; socket.on("pj_corpus_analysis_init", (response) => { + var errorText; + if (response.code === 200) { console.log(`pj_corpus_analysis_init: ${response.code} - ${response.msg}`); if (this.callbacks.init != undefined) {this.callbacks.init(response.payload);} if (this.displays.init != undefined) {this.displays.init.setVisibilityByStatus("success");} } else { - errorText = `Error ${response.payload.code} - ${response.payload.msg}`; + errorText = `Error ${response.code} - ${response.msg}`; if (this.displays.init.errorContainer != undefined) {this.displays.init.errorContainer.innerHTML = `

error ${errorText}

`;} if (this.displays.init != undefined) {this.displays.init.setVisibilityByStatus("error");} console.error(`pj_corpus_analysis_init: ${errorText}`);