0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-02-10 23:36:14 -05:00

🐛 Fixed throwing errors during link redirects

no issue

Errors weren't correctly passed on to Express in the middleware.
This commit is contained in:
Simon Backx 2023-02-08 11:49:15 +01:00 committed by Daniel Lockyer
parent f7aefa2feb
commit b7be02f057
No known key found for this signature in database

View file

@ -85,6 +85,7 @@ class LinkRedirectsService {
* @returns {Promise<void>}
*/
async handleRequest(req, res, next) {
try {
// skip handling if original url doesn't match the prefix
const fullURLWithRedirectPrefix = `${this.#baseURL.pathname}${this.#redirectURLPrefix}`;
if (!req.originalUrl.startsWith(fullURLWithRedirectPrefix)) {
@ -107,6 +108,9 @@ class LinkRedirectsService {
res.setHeader('X-Robots-Tag', 'noindex, nofollow');
return res.redirect(link.to.href);
} catch (e) {
return next(e);
}
}
}