mirror of
https://github.com/TryGhost/Ghost.git
synced 2023-12-13 21:00:40 +01:00
improvement: storage error handling (#7257)
no issue - while testing different situations for custom storage adapters after switching from 0.9 to 0.10, it turned out the error output was not optimal - this PR improves that
This commit is contained in:
parent
6c199afedf
commit
fb4a4817ef
1 changed files with 19 additions and 6 deletions
|
@ -24,14 +24,27 @@ function getStorage(type) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// CASE: load adapter from custom path (.../content/storage)
|
// CASE: load adapter from custom path (.../content/storage)
|
||||||
// CASE: load adapter from default path (.../server/storage)
|
|
||||||
try {
|
try {
|
||||||
storage[storageChoice] = require(config.paths.storagePath.custom + storageChoice);
|
storage[storageChoice] = require(config.paths.storagePath.custom + storageChoice);
|
||||||
} catch (err1) {
|
} catch (err) {
|
||||||
try {
|
// CASE: only throw error if module does exist
|
||||||
storage[storageChoice] = require(config.paths.storagePath.default + storageChoice);
|
if (err.code !== 'MODULE_NOT_FOUND') {
|
||||||
} catch (err2) {
|
throw new errors.IncorrectUsage(err.message);
|
||||||
throw err2;
|
}
|
||||||
|
// CASE: if module not found it can be an error within the adapter (cannot find bluebird for example)
|
||||||
|
else if (err.code === 'MODULE_NOT_FOUND' && err.message.indexOf(config.paths.storagePath.custom + storageChoice) === -1) {
|
||||||
|
throw new errors.IncorrectUsage(err.message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// CASE: either storage[storageChoice] is already set or why check for in the default storage path
|
||||||
|
try {
|
||||||
|
storage[storageChoice] = storage[storageChoice] || require(config.paths.storagePath.default + storageChoice);
|
||||||
|
} catch (err) {
|
||||||
|
if (err.code === 'MODULE_NOT_FOUND') {
|
||||||
|
throw new errors.IncorrectUsage('We cannot find your adpter in: ' + config.paths.storagePath.custom + ' or: ' + config.paths.storagePath.default);
|
||||||
|
} else {
|
||||||
|
throw new errors.IncorrectUsage(err.message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue