diff --git a/src/backups.js b/src/backups.js index 1a93e65e7..4e388dcd5 100644 --- a/src/backups.js +++ b/src/backups.js @@ -158,7 +158,7 @@ function get(backupId, callback) { assert.strictEqual(typeof callback, 'function'); backupdb.get(backupId, function (error, result) { - if (error && error.reason === DatabaseError.NOT_FOUND) return callback(new BackupsError(BackupsError.NOT_FOUND, error)); + if (error && error.reason === DatabaseError.NOT_FOUND) return callback(new BackupsError(BackupsError.NOT_FOUND)); if (error) return callback(new BackupsError(BackupsError.INTERNAL_ERROR, error)); callback(null, result); diff --git a/src/storage/filesystem.js b/src/storage/filesystem.js index f5b6edfc3..68c3fc829 100644 --- a/src/storage/filesystem.js +++ b/src/storage/filesystem.js @@ -68,9 +68,9 @@ function download(apiConfig, sourceFilePath, callback) { assert.strictEqual(typeof sourceFilePath, 'string'); assert.strictEqual(typeof callback, 'function'); - debug('download: %s', sourceFilePath); + debug(`download: ${sourceFilePath}`); - if (!safe.fs.existsSync(sourceFilePath)) return callback(new BackupsError(BackupsError.NOT_FOUND, 'File not found')); + if (!safe.fs.existsSync(sourceFilePath)) return callback(new BackupsError(BackupsError.NOT_FOUND, `File not found: ${sourceFilePath}`)); var fileStream = fs.createReadStream(sourceFilePath); callback(null, fileStream); diff --git a/src/storage/s3.js b/src/storage/s3.js index d7c909a63..929ff52be 100644 --- a/src/storage/s3.js +++ b/src/storage/s3.js @@ -44,6 +44,10 @@ function mockRestore() { var gCachedCaasCredentials = { issueDate: null, credentials: null }; +function S3_NOT_FOUND(error) { + return error.code === 'NoSuchKey' || error.code === 'NotFound' || error.code === 'ENOENT'; +} + function getCaasConfig(apiConfig, callback) { assert.strictEqual(typeof apiConfig, 'object'); assert.strictEqual(typeof callback, 'function'); @@ -170,8 +174,8 @@ function download(apiConfig, backupFilePath, callback) { var multipartDownload = new S3BlockReadStream(s3, params, { blockSize: 64 * 1024 * 1024 /*, logCallback: debug */ }); multipartDownload.on('error', function (error) { - if (error.code === 'NoSuchKey' || error.code === 'ENOENT') { - ps.emit('error', new BackupsError(BackupsError.NOT_FOUND)); + if (S3_NOT_FOUND(error)) { + ps.emit('error', new BackupsError(BackupsError.NOT_FOUND, `Backup not found: ${backupFilePath}`)); } else { debug(`download: ${apiConfig.bucket}:${backupFilePath} s3 stream error.`, error); ps.emit('error', new BackupsError(BackupsError.EXTERNAL_ERROR, error.message || error.code)); // DO sets 'code' @@ -259,7 +263,7 @@ function copy(apiConfig, oldFilePath, newFilePath) { function done(error) { if (error) debug(`copy: s3 copy error when copying ${entry.fullPath}: ${error}`); - if (error && error.code === 'NoSuchKey') return iteratorCallback(new BackupsError(BackupsError.NOT_FOUND, `Old backup not found: ${entry.fullPath}`)); + if (error && S3_NOT_FOUND(error)) return iteratorCallback(new BackupsError(BackupsError.NOT_FOUND, `Old backup not found: ${entry.fullPath}`)); if (error) return iteratorCallback(new BackupsError(BackupsError.EXTERNAL_ERROR, `Error copying ${entry.fullPath} : ${error.code} ${error}`)); iteratorCallback(null);