Skip to content

Commit 6ff8478

Browse files
[DURACOM-344] set error pages status in response
1 parent b076738 commit 6ff8478

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

server.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,7 @@ function cacheCheck(req, res, next) {
398398
});
399399
}
400400
res.locals.ssr = true; // mark response as SSR-generated (enables text compression)
401+
setRequestErrorStatus(req, res);
401402
res.send(cachedCopy.page);
402403

403404
// Tell Express to skip all other handlers for this path
@@ -406,10 +407,26 @@ function cacheCheck(req, res, next) {
406407
} else {
407408
// If nothing found in cache, just continue with next handler
408409
// (This should send the request on to the handler that rerenders the page via SSR
410+
setRequestErrorStatus(req, res);
409411
next();
410412
}
411413
}
412414

415+
/**
416+
* Set request status code when serving an error page from SSR
417+
* @param req
418+
* @param res
419+
*/
420+
function setRequestErrorStatus(req, res) {
421+
if (req.url === '/500') {
422+
res.status(500)
423+
} else if (req.url === '/404') {
424+
res.status(404)
425+
} else if (req.url === '/403') {
426+
res.status(403)
427+
}
428+
}
429+
413430
/**
414431
* Checks if the current request (i.e. page) is found in the given cache. If it is found,
415432
* the cached copy is returned. When found, this method also triggers a re-render via

0 commit comments

Comments
 (0)