Merge pull request #244 from cory-newleaf/patch-1

Updated "getFile" to send 404 for ENOENT errors
This commit is contained in:
Taranveer Virk 2018-06-20 13:38:12 -04:00 committed by GitHub
commit 7fec4b8932
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 23 additions and 1 deletions

View File

@ -210,6 +210,10 @@ StorageService.prototype.getFiles = function(container, options, cb) {
*/
StorageService.prototype.getFile = function(container, file, cb) {
return this.client.getFile(container, file, function(err, f) {
if (err && err.code === 'ENOENT') {
err.statusCode = err.status = 404;
return cb(err);
}
return cb(err, map(f));
});
};

View File

@ -196,6 +196,15 @@ describe('FileSystem based storage provider', function() {
});
});
it('should not get a file from a container', function(done) {
client.getFile('c1', 'f2.txt', function(err, f) {
assert(err);
assert.equal('ENOENT', err.code);
assert(!f);
done();
});
});
it('should destroy a container c1', function(done) {
client.destroyContainer('c1', function(err, container) {
// console.error(err);

View File

@ -133,6 +133,16 @@ describe('Storage service', function() {
});
});
it('should not get a file from a container', function(done) {
storageService.getFile('c1', 'f1.txt', function(err, f) {
assert(err);
assert.equal('ENOENT', err.code);
assert.equal(404, err.status);
assert(!f);
done();
});
});
it('should destroy a container c1', function(done) {
storageService.destroyContainer('c1', function(err, container) {
// console.error(err);
@ -142,4 +152,3 @@ describe('Storage service', function() {
});
});
});