Skip to content

Commit

Permalink
Merge pull request #2269 from Sefaria/node_error_logging
Browse files Browse the repository at this point in the history
feat: Catch and log errors in rendering in Node
  • Loading branch information
akiva10b authored Jan 26, 2025
2 parents 8db35aa + 3eda29b commit 846df25
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions node/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ router.get('/error', function(req, res, next) {
return next(new Error("This is an error and it should be logged to the console"));
});

router.post('/ReaderApp/:cachekey', function(req, res) {
router.post('/ReaderApp/:cachekey', function(req, res, next) {
// timing stored on locals so that it gets returned with the result to be logged
const timer = res.locals.timing = {
start: new Date(),
Expand Down Expand Up @@ -128,11 +128,11 @@ router.post('/ReaderApp/:cachekey', function(req, res) {
delete res.locals.timing.elapsed; // no need to pass this around

res.end(resphtml);
} catch (render_e){
logger.error(render_e);
} catch (render_e) {
return next(render_e);
}
}).catch(error => {
res.status(500).end('Data required for render is missing: ' + error.message);
return next(error);
});
});

Expand Down

0 comments on commit 846df25

Please sign in to comment.