fix: don't crash the server on processing issues

Use a try/catch for async functions

Signed-off-by: boldtrn <boldtrn@gmail.com>
This commit is contained in:
boldtrn 2023-09-26 10:10:00 +02:00
parent 775ea74a2a
commit c3be560fa2

View file

@ -889,6 +889,7 @@ export const serve_rendered = {
app.get( app.get(
util.format(staticPattern, centerPattern), util.format(staticPattern, centerPattern),
async (req, res, next) => { async (req, res, next) => {
try {
const item = repo[req.params.id]; const item = repo[req.params.id];
if (!item) { if (!item) {
return res.sendStatus(404); return res.sendStatus(404);
@ -954,10 +955,14 @@ export const serve_rendered = {
overlay, overlay,
'static', 'static',
); );
} catch (e) {
next(e);
}
}, },
); );
const serveBounds = async (req, res, next) => { const serveBounds = async (req, res, next) => {
try {
const item = repo[req.params.id]; const item = repo[req.params.id];
if (!item) { if (!item) {
return res.sendStatus(404); return res.sendStatus(404);
@ -1031,6 +1036,9 @@ export const serve_rendered = {
overlay, overlay,
'static', 'static',
); );
} catch (e) {
next(e);
}
}; };
const boundsPattern = util.format( const boundsPattern = util.format(
@ -1070,6 +1078,7 @@ export const serve_rendered = {
app.get( app.get(
util.format(staticPattern, autoPattern), util.format(staticPattern, autoPattern),
async (req, res, next) => { async (req, res, next) => {
try {
const item = repo[req.params.id]; const item = repo[req.params.id];
if (!item) { if (!item) {
return res.sendStatus(404); return res.sendStatus(404);
@ -1161,6 +1170,9 @@ export const serve_rendered = {
overlay, overlay,
'static', 'static',
); );
} catch (e) {
next(e);
}
}, },
); );
} }