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

Removed all remaining bluebird catch predicates

refs: https://github.com/TryGhost/Ghost/issues/14882

- The use of predicates is deprecated, and we're working to remove them from everywhere, so that we can remove bluebird
- This should be the final piece of the puzzle in terms of predicates, from here we can start removing bluebird without concern that a predicate somewhere will explode
- Note: some of this code is poorly tested, but the refactors are very straightforward and minimal
This commit is contained in:
Hannah Wolfe 2022-08-24 09:55:52 +01:00
parent af94855349
commit 21231536cb
4 changed files with 87 additions and 83 deletions

View file

@ -40,15 +40,16 @@ class Gravatar {
image: imageUrl
};
})
.catch({statusCode: 404}, function () {
return {
image: undefined
};
})
.catch(function () {
.catch(function (err) {
if (err.statusCode === 404) {
return {
image: undefined
};
}
// ignore error, just resolve with no image url
});
}
}
module.exports = Gravatar;
module.exports = Gravatar;

View file

@ -163,39 +163,41 @@ class ImageSize {
width: dimensions.width,
height: dimensions.height
};
}).catch({code: 'URL_MISSING_INVALID'}, (err) => {
return Promise.reject(new errors.InternalServerError({
message: err.message,
code: 'IMAGE_SIZE_URL',
statusCode: err.statusCode,
context: err.url || imagePath
}));
}).catch({code: 'ETIMEDOUT'}, {code: 'ESOCKETTIMEDOUT'}, {code: 'ECONNRESET'}, {statusCode: 408}, (err) => {
return Promise.reject(new errors.InternalServerError({
message: 'Request timed out.',
code: 'IMAGE_SIZE_URL',
statusCode: err.statusCode,
context: err.url || imagePath
}));
}).catch({code: 'ENOENT'}, {code: 'ENOTFOUND'}, {statusCode: 404}, (err) => {
return Promise.reject(new errors.NotFoundError({
message: 'Image not found.',
code: 'IMAGE_SIZE_URL',
statusCode: err.statusCode,
context: err.url || imagePath
}));
}).catch(function (err) {
if (errors.utils.isGhostError(err)) {
return Promise.reject(err);
}
}).catch((err) => {
if (err.code === 'URL_MISSING_INVALID') {
return Promise.reject(new errors.InternalServerError({
message: err.message,
code: 'IMAGE_SIZE_URL',
statusCode: err.statusCode,
context: err.url || imagePath
}));
} else if (err.code === 'ETIMEDOUT' || err.code === 'ESOCKETTIMEDOUT' || err.code === 'ECONNRESET' || err.statusCode === 408) {
return Promise.reject(new errors.InternalServerError({
message: 'Request timed out.',
code: 'IMAGE_SIZE_URL',
statusCode: err.statusCode,
context: err.url || imagePath
}));
} else if (err.code === 'ENOENT' || err.code === 'ENOTFOUND' || err.statusCode === 404) {
return Promise.reject(new errors.NotFoundError({
message: 'Image not found.',
code: 'IMAGE_SIZE_URL',
statusCode: err.statusCode,
context: err.url || imagePath
}));
} else {
if (errors.utils.isGhostError(err)) {
return Promise.reject(err);
}
return Promise.reject(new errors.InternalServerError({
message: 'Unknown Request error.',
code: 'IMAGE_SIZE_URL',
statusCode: err.statusCode,
context: err.url || imagePath,
err: err
}));
return Promise.reject(new errors.InternalServerError({
message: 'Unknown Request error.',
code: 'IMAGE_SIZE_URL',
statusCode: err.statusCode,
context: err.url || imagePath,
err: err
}));
}
});
}
@ -237,32 +239,34 @@ class ImageSize {
height: dimensions.height
};
})
.catch({code: 'ENOENT'}, (err) => {
return Promise.reject(new errors.NotFoundError({
message: err.message,
code: 'IMAGE_SIZE_STORAGE',
err: err,
context: filePath,
errorDetails: {
originalPath: imagePath,
reqFilePath: filePath
.catch((err) => {
if (err.code === 'ENOENT') {
return Promise.reject(new errors.NotFoundError({
message: err.message,
code: 'IMAGE_SIZE_STORAGE',
err: err,
context: filePath,
errorDetails: {
originalPath: imagePath,
reqFilePath: filePath
}
}));
} else {
if (errors.utils.isGhostError(err)) {
return Promise.reject(err);
}
}));
}).catch((err) => {
if (errors.utils.isGhostError(err)) {
return Promise.reject(err);
}
return Promise.reject(new errors.InternalServerError({
message: err.message,
code: 'IMAGE_SIZE_STORAGE',
err: err,
context: filePath,
errorDetails: {
originalPath: imagePath,
reqFilePath: filePath
}
}));
return Promise.reject(new errors.InternalServerError({
message: err.message,
code: 'IMAGE_SIZE_STORAGE',
err: err,
context: filePath,
errorDetails: {
originalPath: imagePath,
reqFilePath: filePath
}
}));
}
});
}

View file

@ -144,9 +144,6 @@ function doReset(options, tokenParts, settingsAPI) {
updatedUser.set('status', 'active');
return updatedUser.save(options);
})
.catch(errors.ValidationError, (err) => {
return Promise.reject(err);
})
.catch((err) => {
if (errors.utils.isGhostError(err)) {
return Promise.reject(err);

View file

@ -38,23 +38,25 @@ class DefaultSettingsManager {
const defaultFilePath = path.join(this.sourceFolderPath, defaultFileName);
return Promise.resolve(fs.readFile(destinationFilePath, 'utf8'))
.catch({code: 'ENOENT'}, () => {
// CASE: file doesn't exist, copy it from our defaults
return fs.copy(
defaultFilePath,
destinationFilePath
).then(() => {
debug(`'${defaultFileName}' copied to ${this.destinationFolderPath}.`);
});
}).catch((error) => {
// CASE: we might have a permission error, as we can't access the directory
throw new errors.InternalServerError({
message: tpl(messages.ensureSettings, {
path: this.destinationFolderPath
}),
err: error,
context: error.path
});
.catch((err) => {
if (err.code === 'ENOENT') {
// CASE: file doesn't exist, copy it from our defaults
return fs.copy(
defaultFilePath,
destinationFilePath
).then(() => {
debug(`'${defaultFileName}' copied to ${this.destinationFolderPath}.`);
});
} else {
// CASE: we might have a permission error, as we can't access the directory
throw new errors.InternalServerError({
message: tpl(messages.ensureSettings, {
path: this.destinationFolderPath
}),
err: err,
context: err.path
});
}
});
}
}