Skip to content

Commit

Permalink
Improve normal execution error handling
Browse files Browse the repository at this point in the history
- Properly differentiate between bad requests and internal server errors
- Avoid clean up evasion by putting the cleanup in the finally block
  • Loading branch information
Brikaa committed Sep 15, 2023
1 parent b9adb6f commit fe2fc37
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions api/src/api/v2.js
Original file line number Diff line number Diff line change
Expand Up @@ -265,9 +265,13 @@ router.ws('/connect', async (ws, req) => {
});

router.post('/execute', async (req, res) => {
let job;
try {
job = await get_job(req.body);
} catch (error) {
return res.status(400).json(error);
}
try {
const job = await get_job(req.body);

await job.prime();

let result = await job.execute();
Expand All @@ -276,11 +280,17 @@ router.post('/execute', async (req, res) => {
result.run = result.compile;
}

await job.cleanup();

return res.status(200).send(result);
} 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();
}
}
});

Expand Down
Empty file modified packages/bash/5.2.0/build.sh
100644 → 100755
Empty file.

0 comments on commit fe2fc37

Please sign in to comment.