#4: Return a 404 if file doesn't exist

Signed-off-by: Timo Saikkonen <timo.saikkonen@gmail.com>
This commit is contained in:
Timo Saikkonen 2014-12-25 13:21:20 +08:00
parent 58b69236bb
commit 169ee1be21
2 changed files with 11 additions and 0 deletions

View File

@ -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 });
});

View File

@ -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));
});
};