added try catch around sparql query for malformed queries
This commit is contained in:
parent
b4c2a0c88d
commit
59bb42be11
1 changed files with 25 additions and 18 deletions
43
app/index.js
43
app/index.js
|
@ -241,28 +241,35 @@ app.post("/UploadMetafile", upload.single('file'), (req, res) => {
|
||||||
app.post('/sparql', (req, res) => {
|
app.post('/sparql', (req, res) => {
|
||||||
console.log(req.body);
|
console.log(req.body);
|
||||||
const start = async function () {
|
const start = async function () {
|
||||||
let result = [];
|
try {
|
||||||
const bindingsStream = await myEngine.queryBindings(
|
let result = [];
|
||||||
req.body,
|
const bindingsStream = await myEngine.queryBindings(
|
||||||
{
|
req.body,
|
||||||
readOnly: true,
|
{
|
||||||
sources: [{
|
readOnly: true,
|
||||||
type: 'rdfjsSource',
|
sources: [{
|
||||||
value: p2pServer.store
|
type: 'rdfjsSource',
|
||||||
}]
|
value: p2pServer.store
|
||||||
|
}]
|
||||||
|
});
|
||||||
|
bindingsStream.on('data', (binding) => {
|
||||||
|
console.log(binding.toString());
|
||||||
|
result.push(binding);
|
||||||
});
|
});
|
||||||
bindingsStream.on('data', (binding) => {
|
bindingsStream.on('end', () => {
|
||||||
console.log(binding.toString());
|
res.json(JSON.stringify(result));
|
||||||
result.push(binding);
|
});
|
||||||
});
|
bindingsStream.on('error', (err) => {
|
||||||
bindingsStream.on('end', () => {
|
console.error(err);
|
||||||
res.json(JSON.stringify(result));
|
});
|
||||||
});
|
} catch (err) {
|
||||||
bindingsStream.on('error', (err) => {
|
|
||||||
console.error(err);
|
console.error(err);
|
||||||
});
|
res.json("Error occured while querying");
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
start()
|
start()
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////Integration///////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////Integration///////////////////////////////////////////////////////////
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue