0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-03-11 02:12:21 -05:00

🐛 Fixed 'Invalid status code: undefined' in members api (#15973)

fixes https://github.com/TryGhost/Team/issues/2377

When there is an error thrown that is not a Ghost error, there is no
status code in the error. Calling res.writeHead with an undefined status
code, throws an error and crashes Ghost.

This change fixes that and adds logging for those errors.
This commit is contained in:
Simon Backx 2022-12-13 12:32:05 +01:00 committed by GitHub
parent 520b19e313
commit a721e4f2d7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -77,7 +77,10 @@ const deleteSession = async function (req, res) {
res.writeHead(204);
res.end();
} catch (err) {
res.writeHead(err.statusCode, {
if (!err.statusCode) {
logging.error(err);
}
res.writeHead(err.statusCode ?? 500, {
'Content-Type': 'text/plain;charset=UTF-8'
});
res.end(err.message);
@ -111,7 +114,10 @@ const deleteSuppression = async function (req, res) {
res.writeHead(204);
res.end();
} catch (err) {
res.writeHead(err.statusCode, {
if (!err.statusCode) {
logging.error(err);
}
res.writeHead(err.statusCode ?? 500, {
'Content-Type': 'text/plain;charset=UTF-8'
});
res.end(err.message);
@ -194,7 +200,10 @@ const updateMemberData = async function (req, res) {
res.json(null);
}
} catch (err) {
res.writeHead(err.statusCode, {
if (!err.statusCode) {
logging.error(err);
}
res.writeHead(err.statusCode ?? 500, {
'Content-Type': 'text/plain;charset=UTF-8'
});
res.end(err.message);