mirror of
https://gitlab.ub.uni-bielefeld.de/sfb1288inf/nopaque.git
synced 2024-12-24 10:34:17 +00:00
Fix Error handling in corpus analysis app
This commit is contained in:
parent
7936ac270b
commit
a9f05fffdf
@ -62,13 +62,7 @@ CQI_FUNCTION_NAMES: List[str] = [
|
|||||||
|
|
||||||
@socketio.on('cqi', namespace=ns)
|
@socketio.on('cqi', namespace=ns)
|
||||||
@socketio_login_required
|
@socketio_login_required
|
||||||
def cqi_over_sio(fn_data):
|
def cqi_over_sio(fn_name: str, fn_args: Dict = {}):
|
||||||
try:
|
|
||||||
fn_name: str = fn_data['fn_name']
|
|
||||||
except KeyError:
|
|
||||||
return {'code': 400, 'msg': 'Bad Request'}
|
|
||||||
fn_name: str = fn_data['fn_name']
|
|
||||||
fn_args: Dict = fn_data.get('fn_args', {})
|
|
||||||
try:
|
try:
|
||||||
cqi_client: CQiClient = session['cqi_over_sio']['cqi_client']
|
cqi_client: CQiClient = session['cqi_over_sio']['cqi_client']
|
||||||
cqi_client_lock: Lock = session['cqi_over_sio']['cqi_client_lock']
|
cqi_client_lock: Lock = session['cqi_over_sio']['cqi_client_lock']
|
||||||
@ -77,7 +71,6 @@ def cqi_over_sio(fn_data):
|
|||||||
if fn_name in CQI_FUNCTION_NAMES:
|
if fn_name in CQI_FUNCTION_NAMES:
|
||||||
fn: Callable = getattr(cqi_client.api, fn_name)
|
fn: Callable = getattr(cqi_client.api, fn_name)
|
||||||
elif fn_name in CQI_EXTENSION_FUNCTION_NAMES:
|
elif fn_name in CQI_EXTENSION_FUNCTION_NAMES:
|
||||||
fn_args['cqi_client'] = cqi_client
|
|
||||||
fn: Callable = getattr(extensions_module, fn_name)
|
fn: Callable = getattr(extensions_module, fn_name)
|
||||||
else:
|
else:
|
||||||
return {'code': 400, 'msg': 'Bad Request'}
|
return {'code': 400, 'msg': 'Bad Request'}
|
||||||
@ -92,14 +85,14 @@ def cqi_over_sio(fn_data):
|
|||||||
return {'code': 400, 'msg': 'Bad Request'}
|
return {'code': 400, 'msg': 'Bad Request'}
|
||||||
cqi_client_lock.acquire()
|
cqi_client_lock.acquire()
|
||||||
try:
|
try:
|
||||||
return_value = fn(**fn_args)
|
fn_return_value = fn(**fn_args)
|
||||||
except BrokenPipeError:
|
except BrokenPipeError:
|
||||||
return_value = {
|
fn_return_value = {
|
||||||
'code': 500,
|
'code': 500,
|
||||||
'msg': 'Internal Server Error'
|
'msg': 'Internal Server Error'
|
||||||
}
|
}
|
||||||
except CQiException as e:
|
except CQiException as e:
|
||||||
return_value = {
|
return {
|
||||||
'code': 502,
|
'code': 502,
|
||||||
'msg': 'Bad Gateway',
|
'msg': 'Bad Gateway',
|
||||||
'payload': {
|
'payload': {
|
||||||
@ -110,11 +103,11 @@ def cqi_over_sio(fn_data):
|
|||||||
}
|
}
|
||||||
finally:
|
finally:
|
||||||
cqi_client_lock.release()
|
cqi_client_lock.release()
|
||||||
if isinstance(return_value, CQiStatus):
|
if isinstance(fn_return_value, CQiStatus):
|
||||||
payload = {
|
payload = {
|
||||||
'code': return_value.code,
|
'code': fn_return_value.code,
|
||||||
'msg': return_value.__class__.__name__
|
'msg': fn_return_value.__class__.__name__
|
||||||
}
|
}
|
||||||
else:
|
else:
|
||||||
payload = return_value
|
payload = fn_return_value
|
||||||
return {'code': 200, 'msg': 'OK', 'payload': payload}
|
return {'code': 200, 'msg': 'OK', 'payload': payload}
|
||||||
|
@ -22,20 +22,22 @@ CQI_EXTENSION_FUNCTION_NAMES: List[str] = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
def ext_corpus_update_db(cqi_client: CQiClient, corpus: str):
|
def ext_corpus_update_db(corpus: str):
|
||||||
db_corpus = Corpus.query.get(session['cqi_over_sio']['corpus_id'])
|
db_corpus = Corpus.query.get(session['cqi_over_sio']['corpus_id'])
|
||||||
|
cqi_client: CQiClient = session['cqi_over_sio']['cqi_client']
|
||||||
cqi_corpus = cqi_client.corpora.get(corpus)
|
cqi_corpus = cqi_client.corpora.get(corpus)
|
||||||
db_corpus.num_tokens = cqi_corpus.size
|
db_corpus.num_tokens = cqi_corpus.size
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
return StatusOk()
|
return StatusOk()
|
||||||
|
|
||||||
|
|
||||||
def ext_corpus_static_data(cqi_client: CQiClient, corpus: str) -> Dict:
|
def ext_corpus_static_data(corpus: str) -> Dict:
|
||||||
db_corpus = Corpus.query.get(session['cqi_over_sio']['corpus_id'])
|
db_corpus = Corpus.query.get(session['cqi_over_sio']['corpus_id'])
|
||||||
static_corpus_data_file = os.path.join(db_corpus.path, 'cwb', 'static.json')
|
static_corpus_data_file = os.path.join(db_corpus.path, 'cwb', 'static.json')
|
||||||
if os.path.exists(static_corpus_data_file):
|
if os.path.exists(static_corpus_data_file):
|
||||||
with open(static_corpus_data_file, 'r') as f:
|
with open(static_corpus_data_file, 'r') as f:
|
||||||
return json.load(f)
|
return json.load(f)
|
||||||
|
cqi_client: CQiClient = session['cqi_over_sio']['cqi_client']
|
||||||
cqi_corpus = cqi_client.corpora.get(corpus)
|
cqi_corpus = cqi_client.corpora.get(corpus)
|
||||||
##########################################################################
|
##########################################################################
|
||||||
# A faster way to get cpos boundaries for smaller s_attrs #
|
# A faster way to get cpos boundaries for smaller s_attrs #
|
||||||
@ -137,11 +139,11 @@ def ext_corpus_static_data(cqi_client: CQiClient, corpus: str) -> Dict:
|
|||||||
|
|
||||||
|
|
||||||
def ext_corpus_paginate_corpus(
|
def ext_corpus_paginate_corpus(
|
||||||
cqi_client: CQiClient,
|
|
||||||
corpus: str,
|
corpus: str,
|
||||||
page: int = 1,
|
page: int = 1,
|
||||||
per_page: int = 20
|
per_page: int = 20
|
||||||
) -> Dict:
|
) -> Dict:
|
||||||
|
cqi_client: CQiClient = session['cqi_over_sio']['cqi_client']
|
||||||
cqi_corpus = cqi_client.corpora.get(corpus)
|
cqi_corpus = cqi_client.corpora.get(corpus)
|
||||||
# Sanity checks
|
# Sanity checks
|
||||||
if (
|
if (
|
||||||
@ -182,13 +184,13 @@ def ext_corpus_paginate_corpus(
|
|||||||
|
|
||||||
|
|
||||||
def ext_cqp_paginate_subcorpus(
|
def ext_cqp_paginate_subcorpus(
|
||||||
cqi_client: CQiClient,
|
|
||||||
subcorpus: str,
|
subcorpus: str,
|
||||||
context: int = 50,
|
context: int = 50,
|
||||||
page: int = 1,
|
page: int = 1,
|
||||||
per_page: int = 20
|
per_page: int = 20
|
||||||
) -> Dict:
|
) -> Dict:
|
||||||
corpus_name, subcorpus_name = subcorpus.split(':', 1)
|
corpus_name, subcorpus_name = subcorpus.split(':', 1)
|
||||||
|
cqi_client: CQiClient = session['cqi_over_sio']['cqi_client']
|
||||||
cqi_corpus = cqi_client.corpora.get(corpus_name)
|
cqi_corpus = cqi_client.corpora.get(corpus_name)
|
||||||
cqi_subcorpus = cqi_corpus.subcorpora.get(subcorpus_name)
|
cqi_subcorpus = cqi_corpus.subcorpora.get(subcorpus_name)
|
||||||
# Sanity checks
|
# Sanity checks
|
||||||
@ -230,12 +232,12 @@ def ext_cqp_paginate_subcorpus(
|
|||||||
|
|
||||||
|
|
||||||
def ext_cqp_partial_export_subcorpus(
|
def ext_cqp_partial_export_subcorpus(
|
||||||
cqi_client: CQiClient,
|
|
||||||
subcorpus: str,
|
subcorpus: str,
|
||||||
match_id_list: list,
|
match_id_list: list,
|
||||||
context: int = 50
|
context: int = 50
|
||||||
) -> Dict:
|
) -> Dict:
|
||||||
corpus_name, subcorpus_name = subcorpus.split(':', 1)
|
corpus_name, subcorpus_name = subcorpus.split(':', 1)
|
||||||
|
cqi_client: CQiClient = session['cqi_over_sio']['cqi_client']
|
||||||
cqi_corpus = cqi_client.corpora.get(corpus_name)
|
cqi_corpus = cqi_client.corpora.get(corpus_name)
|
||||||
cqi_subcorpus = cqi_corpus.subcorpora.get(subcorpus_name)
|
cqi_subcorpus = cqi_corpus.subcorpora.get(subcorpus_name)
|
||||||
cqi_subcorpus_partial_export = partial_export_subcorpus(cqi_subcorpus, match_id_list, context=context)
|
cqi_subcorpus_partial_export = partial_export_subcorpus(cqi_subcorpus, match_id_list, context=context)
|
||||||
@ -243,11 +245,11 @@ def ext_cqp_partial_export_subcorpus(
|
|||||||
|
|
||||||
|
|
||||||
def ext_cqp_export_subcorpus(
|
def ext_cqp_export_subcorpus(
|
||||||
cqi_client: CQiClient,
|
|
||||||
subcorpus: str,
|
subcorpus: str,
|
||||||
context: int = 50
|
context: int = 50
|
||||||
) -> Dict:
|
) -> Dict:
|
||||||
corpus_name, subcorpus_name = subcorpus.split(':', 1)
|
corpus_name, subcorpus_name = subcorpus.split(':', 1)
|
||||||
|
cqi_client: CQiClient = session['cqi_over_sio']['cqi_client']
|
||||||
cqi_corpus = cqi_client.corpora.get(corpus_name)
|
cqi_corpus = cqi_client.corpora.get(corpus_name)
|
||||||
cqi_subcorpus = cqi_corpus.subcorpora.get(subcorpus_name)
|
cqi_subcorpus = cqi_corpus.subcorpora.get(subcorpus_name)
|
||||||
cqi_subcorpus_export = export_subcorpus(cqi_subcorpus, context=context)
|
cqi_subcorpus_export = export_subcorpus(cqi_subcorpus, context=context)
|
||||||
|
@ -100,14 +100,13 @@ class CorpusAnalysisApp {
|
|||||||
this.elements.m.initModal.close();
|
this.elements.m.initModal.close();
|
||||||
},
|
},
|
||||||
(cqiError) => {
|
(cqiError) => {
|
||||||
|
let errorString = `${cqiError.code}: ${cqiError.constructor.name}`;
|
||||||
let errorsElement = this.elements.initModal.querySelector('.errors');
|
let errorsElement = this.elements.initModal.querySelector('.errors');
|
||||||
let progressElement = this.elements.initModal.querySelector('.progress');
|
let progressElement = this.elements.initModal.querySelector('.progress');
|
||||||
errorsElement.innerText = JSON.stringify(cqiError);
|
errorsElement.innerText = errorString;
|
||||||
errorsElement.classList.remove('hide');
|
errorsElement.classList.remove('hide');
|
||||||
|
app.flash(errorString, 'error');
|
||||||
progressElement.classList.add('hide');
|
progressElement.classList.add('hide');
|
||||||
if ('payload' in cqiError && 'code' in cqiError.payload && 'msg' in cqiError.payload) {
|
|
||||||
app.flash(`${cqiError.payload.code}: ${cqiError.payload.msg}`, 'error');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -68,13 +68,11 @@ class CorpusAnalysisConcordance {
|
|||||||
this.elements.progress.classList.add('hide');
|
this.elements.progress.classList.add('hide');
|
||||||
this.app.enableActionElements();
|
this.app.enableActionElements();
|
||||||
},
|
},
|
||||||
(cqiStatus) => {
|
(cqiError) => {
|
||||||
// TODDO: CHECK THIS!
|
let errorString = `${cqiError.code}: ${cqiError.constructor.name}`;
|
||||||
this.elements.error.innerText = JSON.stringify(cqiStatus);
|
this.elements.error.innerText = errorString;
|
||||||
this.elements.error.classList.remove('hide');
|
this.elements.error.classList.remove('hide');
|
||||||
if ('payload' in cqiStatus && 'code' in cqiStatus.payload && 'msg' in cqiStatus.payload) {
|
app.flash(errorString, 'error');
|
||||||
app.flash(`${cqiStatus.payload.code}: ${cqiStatus.payload.msg}`, 'error');
|
|
||||||
}
|
|
||||||
this.elements.progress.classList.add('hide');
|
this.elements.progress.classList.add('hide');
|
||||||
this.app.enableActionElements();
|
this.app.enableActionElements();
|
||||||
}
|
}
|
||||||
@ -313,8 +311,9 @@ class CorpusAnalysisConcordance {
|
|||||||
this.clearSubcorpusPagination();
|
this.clearSubcorpusPagination();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
(cQiError) => {
|
(cqiError) => {
|
||||||
app.flash(`${cQiError.payload.code}: ${cQiError.payload.msg}`, 'error');
|
let errorString = `${cqiError.code}: ${cqiError.constructor.name}`;
|
||||||
|
app.flash(errorString, 'error');
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
@ -45,11 +45,10 @@ class CorpusAnalysisReader {
|
|||||||
this.app.enableActionElements();
|
this.app.enableActionElements();
|
||||||
},
|
},
|
||||||
(cqiError) => {
|
(cqiError) => {
|
||||||
this.elements.error.innerText = JSON.stringify(error);
|
let errorString = `${cqiError.code}: ${cqiError.constructor.name}`;
|
||||||
|
this.elements.error.innerText = errorString;
|
||||||
this.elements.error.classList.remove('hide');
|
this.elements.error.classList.remove('hide');
|
||||||
if ('payload' in error && 'code' in error.payload && 'msg' in error.payload) {
|
app.flash(errorString, 'error');
|
||||||
app.flash(`${error.payload.code}: ${error.payload.msg}`, 'error');
|
|
||||||
}
|
|
||||||
this.elements.progress.classList.add('hide');
|
this.elements.progress.classList.add('hide');
|
||||||
this.app.enableActionElements();
|
this.app.enableActionElements();
|
||||||
}
|
}
|
||||||
|
@ -30,14 +30,12 @@ cqi.api.APIClient = class APIClient {
|
|||||||
// if (timeoutError) {
|
// if (timeoutError) {
|
||||||
// reject(timeoutError);
|
// reject(timeoutError);
|
||||||
// }
|
// }
|
||||||
this.socket.emit('cqi', {fn_name: fn_name, fn_args: fn_args}, (response) => {
|
this.socket.emit('cqi', fn_name, fn_args, (response) => {
|
||||||
if (response.code === 200) {
|
if (response.code === 200) {
|
||||||
resolve(response.payload);
|
resolve(response.payload);
|
||||||
}
|
} else if (response.code === 500) {
|
||||||
if (response.code === 500) {
|
|
||||||
reject(new Error(`[${response.code}] ${response.msg}`));
|
reject(new Error(`[${response.code}] ${response.msg}`));
|
||||||
}
|
} else if (response.code === 502) {
|
||||||
if (response.code === 502) {
|
|
||||||
reject(new cqi.errors.lookup[response.payload.code]());
|
reject(new cqi.errors.lookup[response.payload.code]());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user