Skip to content

Commit

Permalink
Merge pull request #4 from adityaraj-28/error_handling
Browse files Browse the repository at this point in the history
send 500 on exception
  • Loading branch information
adityaraj-28 committed Jun 19, 2023
2 parents db98e5b + 3b135bc commit f134e22
Showing 1 changed file with 20 additions and 15 deletions.
35 changes: 20 additions & 15 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,27 @@ let crawlProcess = null;
let fixedArgs = createArgsFromYAML();

app.post("/crawl", (req, res) => {
const reqDict = { ...req.body };
const requiredKeys = ["url", "collection", "id"];
const missingKeys = requiredKeys.filter((key) => !(key in reqDict));
if (missingKeys.length === 0) {
const args = [
"--url", reqDict.url,
"--collection", String(reqDict.collection),
"--id", String(reqDict.url)
];
args.push(...fixedArgs);

crawlProcess = child_process.spawnSync("crawl", args, {stdio: "inherit"});
res.status(200).json({info: `${reqDict.url} crawl finished`});
} else {
res.status(404).json({error: "Ensure that url, collection and id is present as keys in json"});
try {
const reqDict = {...req.body};
const requiredKeys = ["url", "collection", "id"];
const missingKeys = requiredKeys.filter((key) => !(key in reqDict));
if (missingKeys.length === 0) {
const args = [
"--url", reqDict.url,
"--collection", String(reqDict.collection),
"--id", String(reqDict.url)
];
args.push(...fixedArgs);

crawlProcess = child_process.spawnSync("crawl", args, {stdio: "inherit"});
res.status(200).json({info: `${reqDict.url} crawl finished`});
} else {
res.status(404).json({error: "Ensure that url, collection and id is present as keys in json"});
}
} catch (e) {
res.status(500).json({error: e.message});
}

});


Expand Down

0 comments on commit f134e22

Please sign in to comment.