Skip to content

Commit

Permalink
Comments explaining the try-catch flow
Browse files Browse the repository at this point in the history
  • Loading branch information
Brikaa committed Sep 16, 2023
1 parent 040e19f commit 6a47869
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions api/src/api/v2.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ router.ws('/connect', async (ws, req) => {
} finally {
await job.cleanup();
}
ws.close(4999, 'Job Completed');
ws.close(4999, 'Job Completed'); // Will not execute if an error is thrown above
} else {
ws.close(4000, 'Already Initialized');
}
Expand Down Expand Up @@ -293,10 +293,10 @@ router.post('/execute', async (req, res) => {
return res.status(500).send();
} finally {
try {
await job.cleanup();
await job.cleanup(); // This gets executed before the returns in try/catch
} catch (error) {
logger.error(`Error cleaning up job: ${job.uuid}:\n${error}`);
return res.status(500).send();
return res.status(500).send(); // On error, this replaces the return in the outer try-catch
}
}
});
Expand Down

0 comments on commit 6a47869

Please sign in to comment.