Skip to content

Commit

Permalink
Rethrow developer errors. Closes #103
Browse files Browse the repository at this point in the history
  • Loading branch information
kanongil committed Nov 3, 2017
1 parent f248b2e commit bac2072
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 4 deletions.
8 changes: 7 additions & 1 deletion lib/directory.js
Expand Up @@ -5,6 +5,7 @@
const Path = require('path');

const Boom = require('boom');
const Bounce = require('bounce');
const Hoek = require('hoek');
const Joi = require('joi');

Expand Down Expand Up @@ -111,6 +112,7 @@ exports.handler = function (route, options) {
return await File.load(path, request, fileOptions);
}
catch (err) {
Bounce.ignore(err, 'boom');
error = err;
}

Expand All @@ -125,7 +127,9 @@ exports.handler = function (route, options) {
try {
return await File.load(path + '.' + settings.defaultExtension, request, fileOptions);
}
catch (err) { }
catch (err) {
Bounce.ignore(err, 'boom');
}
}

return;
Expand Down Expand Up @@ -164,6 +168,7 @@ exports.handler = function (route, options) {
return await File.load(indexFile, request, fileOptions);
}
catch (err) {
Bounce.ignore(err, 'boom');

// Directory

Expand Down Expand Up @@ -203,6 +208,7 @@ internals.generateListing = async function (path, resource, selection, hasTraili
files = await Fs.readdir(path);
}
catch (err) {
Bounce.rethrow(err, 'system');
throw Boom.internal('Error accessing directory', err);
}

Expand Down
2 changes: 2 additions & 0 deletions lib/etag.js
Expand Up @@ -5,6 +5,7 @@
const Crypto = require('crypto');

const Boom = require('boom');
const Bounce = require('bounce');
const LruCache = require('lru-cache');


Expand Down Expand Up @@ -83,6 +84,7 @@ internals.hashFile = async function (response) {
return hash.read();
}
catch (err) {
Bounce.rethrow(err, 'system');
throw Boom.boomify(err, { message: 'Failed to hash file' });
}
};
Expand Down
3 changes: 2 additions & 1 deletion lib/file.js
Expand Up @@ -6,6 +6,7 @@ const Path = require('path');

const Ammo = require('ammo');
const Boom = require('boom');
const Bounce = require('bounce');
const Hoek = require('hoek');
const Joi = require('joi');

Expand Down Expand Up @@ -132,7 +133,6 @@ internals.prepare = async function (response) {
return response;
}
catch (err) {

internals.close(response);
throw err;
}
Expand All @@ -157,6 +157,7 @@ internals.marshal = async function (response) {
}
catch (err) {
gzFile.close();
Bounce.ignore(err, 'boom');
}

if (stat) {
Expand Down
5 changes: 4 additions & 1 deletion lib/fs.js
Expand Up @@ -5,6 +5,7 @@
const Util = require('util');

const Boom = require('boom');
const Bounce = require('bounce');
const Hoek = require('hoek');


Expand Down Expand Up @@ -70,7 +71,9 @@ exports.File.prototype.stat = async function () {
}
catch (err) {
this.close(this.fd);
throw err.isBoom ? err : Boom.boomify(err, { message: 'Failed to stat file' });

Bounce.rethrow(err, ['boom', 'system']);
throw Boom.boomify(err, { message: 'Failed to stat file' });
}
};

Expand Down
3 changes: 2 additions & 1 deletion package.json
@@ -1,7 +1,7 @@
{
"name": "inert",
"description": "Static file and directory handlers plugin for hapi.js",
"version": "5.0.0",
"version": "5.0.1",
"repository": "https://github.com/hapijs/inert.git",
"main": "lib/index.js",
"keywords": [
Expand All @@ -20,6 +20,7 @@
"dependencies": {
"ammo": "3.x.x",
"boom": "7.x.x",
"bounce": "1.x.x",
"hoek": "5.x.x",
"joi": "13.x.x",
"lru-cache": "4.1.x"
Expand Down

0 comments on commit bac2072

Please sign in to comment.