Improve normal execution error handling
- Properly differentiate between bad requests and internal server errors - Avoid clean up evasion by putting the cleanup in the finally block
This commit is contained in:
parent
b9adb6f854
commit
fe2fc374aa
|
@ -265,9 +265,13 @@ router.ws('/connect', async (ws, req) => {
|
||||||
});
|
});
|
||||||
|
|
||||||
router.post('/execute', async (req, res) => {
|
router.post('/execute', async (req, res) => {
|
||||||
|
let job;
|
||||||
|
try {
|
||||||
|
job = await get_job(req.body);
|
||||||
|
} catch (error) {
|
||||||
|
return res.status(400).json(error);
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
const job = await get_job(req.body);
|
|
||||||
|
|
||||||
await job.prime();
|
await job.prime();
|
||||||
|
|
||||||
let result = await job.execute();
|
let result = await job.execute();
|
||||||
|
@ -276,11 +280,17 @@ router.post('/execute', async (req, res) => {
|
||||||
result.run = result.compile;
|
result.run = result.compile;
|
||||||
}
|
}
|
||||||
|
|
||||||
await job.cleanup();
|
|
||||||
|
|
||||||
return res.status(200).send(result);
|
return res.status(200).send(result);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return res.status(400).json(error);
|
logger.error(`Error executing job: ${job.uuid}:\n${error}`);
|
||||||
|
return res.status(500).send();
|
||||||
|
} finally {
|
||||||
|
try {
|
||||||
|
await job.cleanup();
|
||||||
|
} catch (error) {
|
||||||
|
logger.error(`Error cleaning up job: ${job.uuid}:\n${error}`);
|
||||||
|
return res.status(500).send();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue