Handled EENVELOPE errors when generating magic link

refs https://github.com/TryGhost/Team/issues/1259

These errors are thrown by nodemailer and can occur when an invalid
email address is used. Without special handling these cause a 500 error.
This commit is contained in:
Fabien egg O'Carroll 2021-12-16 09:25:32 +02:00
parent d6d4920fee
commit 2e7bb3e67e

View File

@ -300,6 +300,11 @@ module.exports = class RouterController {
res.writeHead(201);
return res.end('Created.');
} catch (err) {
if (err.code === 'EENVELOPE') {
logging.error(err);
res.writeHead(400);
return res.end('Bad Request.');
}
const statusCode = (err && err.statusCode) || 500;
logging.error(err);
res.writeHead(statusCode);