diff --git a/lib/storage-handler.js b/lib/storage-handler.js index f56c669..5a75437 100644 --- a/lib/storage-handler.js +++ b/lib/storage-handler.js @@ -118,9 +118,16 @@ exports.download = function (provider, req, res, container, file, cb) { container: container || req && req.params.container, remote: file || req && req.params.file }); + res.type(file); reader.pipe(res); reader.on('error', function (err) { + if (err.code === 'ENOENT') { + res.type('application/json'); + res.send(404, { error: err }); + return; + } + res.type('application/json'); res.send(500, { error: err }); }); diff --git a/lib/storage-service.js b/lib/storage-service.js index 3f4b755..f71a04a 100644 --- a/lib/storage-service.js +++ b/lib/storage-service.js @@ -92,6 +92,10 @@ StorageService.prototype.destroyContainer = function (container, cb) { */ StorageService.prototype.getContainer = function (container, cb) { return this.client.getContainer(container, function (err, container) { + if (err && err.code === 'ENOENT') { + err.statusCode = err.status = 404; + return cb(err); + } return cb(err, map(container)); }); };