From 59bb42be11807bd9b73f2e800841ef2ca0db313e Mon Sep 17 00:00:00 2001 From: Josip Milovac Date: Tue, 20 Dec 2022 11:34:11 +1100 Subject: [PATCH] added try catch around sparql query for malformed queries --- app/index.js | 43 +++++++++++++++++++++++++------------------ 1 file changed, 25 insertions(+), 18 deletions(-) diff --git a/app/index.js b/app/index.js index ca2d326..3ddde96 100644 --- a/app/index.js +++ b/app/index.js @@ -241,28 +241,35 @@ app.post("/UploadMetafile", upload.single('file'), (req, res) => { app.post('/sparql', (req, res) => { console.log(req.body); const start = async function () { - let result = []; - const bindingsStream = await myEngine.queryBindings( - req.body, - { - readOnly: true, - sources: [{ - type: 'rdfjsSource', - value: p2pServer.store - }] + try { + let result = []; + const bindingsStream = await myEngine.queryBindings( + req.body, + { + readOnly: true, + sources: [{ + type: 'rdfjsSource', + value: p2pServer.store + }] + }); + bindingsStream.on('data', (binding) => { + console.log(binding.toString()); + result.push(binding); }); - bindingsStream.on('data', (binding) => { - console.log(binding.toString()); - result.push(binding); - }); - bindingsStream.on('end', () => { - res.json(JSON.stringify(result)); - }); - bindingsStream.on('error', (err) => { + bindingsStream.on('end', () => { + res.json(JSON.stringify(result)); + }); + bindingsStream.on('error', (err) => { + console.error(err); + }); + } catch (err) { console.error(err); - }); + res.json("Error occured while querying"); + } }; + start() + }); ///////////////////////////////////////////////////////////Integration///////////////////////////////////////////////////////////