From 970ecc79018f5c0edac1a53b8a185d1208b50225 Mon Sep 17 00:00:00 2001 From: Cory Gottschalk Date: Tue, 24 Apr 2018 13:52:45 -0700 Subject: [PATCH 1/2] Updated "getFile" to send a 404 for ENOENT errors getFile sends a 500 error response when the requested file cannot be found, but the status code probably should be 404. This change sets the status of the error to 404 when the error code is "ENOENT". --- lib/storage-service.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/storage-service.js b/lib/storage-service.js index b17fe57..391a529 100644 --- a/lib/storage-service.js +++ b/lib/storage-service.js @@ -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)); }); }; From db669b1543bdbff69aeeb70918fb7b98187cd802 Mon Sep 17 00:00:00 2001 From: Cory Gottschalk Date: Tue, 12 Jun 2018 20:31:30 -0700 Subject: [PATCH 2/2] added missing tests Added 2 tests to validate the error responses when a file is not found --- test/fs.test.js | 9 +++++++++ test/storage-service.test.js | 11 ++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/test/fs.test.js b/test/fs.test.js index 01c010e..767d6bf 100644 --- a/test/fs.test.js +++ b/test/fs.test.js @@ -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); diff --git a/test/storage-service.test.js b/test/storage-service.test.js index 863a54a..0c312dd 100644 --- a/test/storage-service.test.js +++ b/test/storage-service.test.js @@ -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() { }); }); }); -