0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-02-10 23:36: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,12 +40,13 @@ class Gravatar {
image: imageUrl image: imageUrl
}; };
}) })
.catch({statusCode: 404}, function () { .catch(function (err) {
if (err.statusCode === 404) {
return { return {
image: undefined image: undefined
}; };
}) }
.catch(function () {
// ignore error, just resolve with no image url // ignore error, just resolve with no image url
}); });
} }

View file

@ -163,28 +163,29 @@ class ImageSize {
width: dimensions.width, width: dimensions.width,
height: dimensions.height height: dimensions.height
}; };
}).catch({code: 'URL_MISSING_INVALID'}, (err) => { }).catch((err) => {
if (err.code === 'URL_MISSING_INVALID') {
return Promise.reject(new errors.InternalServerError({ return Promise.reject(new errors.InternalServerError({
message: err.message, message: err.message,
code: 'IMAGE_SIZE_URL', code: 'IMAGE_SIZE_URL',
statusCode: err.statusCode, statusCode: err.statusCode,
context: err.url || imagePath context: err.url || imagePath
})); }));
}).catch({code: 'ETIMEDOUT'}, {code: 'ESOCKETTIMEDOUT'}, {code: 'ECONNRESET'}, {statusCode: 408}, (err) => { } else if (err.code === 'ETIMEDOUT' || err.code === 'ESOCKETTIMEDOUT' || err.code === 'ECONNRESET' || err.statusCode === 408) {
return Promise.reject(new errors.InternalServerError({ return Promise.reject(new errors.InternalServerError({
message: 'Request timed out.', message: 'Request timed out.',
code: 'IMAGE_SIZE_URL', code: 'IMAGE_SIZE_URL',
statusCode: err.statusCode, statusCode: err.statusCode,
context: err.url || imagePath context: err.url || imagePath
})); }));
}).catch({code: 'ENOENT'}, {code: 'ENOTFOUND'}, {statusCode: 404}, (err) => { } else if (err.code === 'ENOENT' || err.code === 'ENOTFOUND' || err.statusCode === 404) {
return Promise.reject(new errors.NotFoundError({ return Promise.reject(new errors.NotFoundError({
message: 'Image not found.', message: 'Image not found.',
code: 'IMAGE_SIZE_URL', code: 'IMAGE_SIZE_URL',
statusCode: err.statusCode, statusCode: err.statusCode,
context: err.url || imagePath context: err.url || imagePath
})); }));
}).catch(function (err) { } else {
if (errors.utils.isGhostError(err)) { if (errors.utils.isGhostError(err)) {
return Promise.reject(err); return Promise.reject(err);
} }
@ -196,6 +197,7 @@ class ImageSize {
context: err.url || imagePath, context: err.url || imagePath,
err: err err: err
})); }));
}
}); });
} }
@ -237,7 +239,8 @@ class ImageSize {
height: dimensions.height height: dimensions.height
}; };
}) })
.catch({code: 'ENOENT'}, (err) => { .catch((err) => {
if (err.code === 'ENOENT') {
return Promise.reject(new errors.NotFoundError({ return Promise.reject(new errors.NotFoundError({
message: err.message, message: err.message,
code: 'IMAGE_SIZE_STORAGE', code: 'IMAGE_SIZE_STORAGE',
@ -248,7 +251,7 @@ class ImageSize {
reqFilePath: filePath reqFilePath: filePath
} }
})); }));
}).catch((err) => { } else {
if (errors.utils.isGhostError(err)) { if (errors.utils.isGhostError(err)) {
return Promise.reject(err); return Promise.reject(err);
} }
@ -263,6 +266,7 @@ class ImageSize {
reqFilePath: filePath reqFilePath: filePath
} }
})); }));
}
}); });
} }

View file

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

View file

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