diff options
author | Samy Pessé <samypesse@gmail.com> | 2016-02-11 10:07:15 +0100 |
---|---|---|
committer | Samy Pessé <samypesse@gmail.com> | 2016-02-11 10:07:15 +0100 |
commit | 52c4dc49cf460dad4edc42457ba9e3ca4c7674d5 (patch) | |
tree | 6d5d123756c8d79ab5add4660e7b66beb3e89736 /lib/utils/path.js | |
parent | 44ad70320a0d0b907702c57e560c6a60373c9bca (diff) | |
download | gitbook-52c4dc49cf460dad4edc42457ba9e3ca4c7674d5.zip gitbook-52c4dc49cf460dad4edc42457ba9e3ca4c7674d5.tar.gz gitbook-52c4dc49cf460dad4edc42457ba9e3ca4c7674d5.tar.bz2 |
Normalize errors
Diffstat (limited to 'lib/utils/path.js')
-rw-r--r-- | lib/utils/path.js | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/lib/utils/path.js b/lib/utils/path.js index 2d722a5..f195d6c 100644 --- a/lib/utils/path.js +++ b/lib/utils/path.js @@ -1,6 +1,8 @@ var _ = require('lodash'); var path = require('path'); +var error = require('./error'); + // Normalize a filename function normalizePath(filename) { return path.normalize(filename); @@ -15,7 +17,7 @@ function isInRoot(root, filename) { // Resolve paths in a specific folder // Throw error if file is outside this folder function resolveInRoot(root) { - var input, result, err; + var input, result; input = _.chain(arguments) .toArray() @@ -31,9 +33,10 @@ function resolveInRoot(root) { result = path.resolve(root, input); if (!isInRoot(root, result)) { - err = new Error('EACCESS: "' + result + '" not in "' + root + '"'); - err.code = 'EACCESS'; - throw err; + throw new error.FileOutOfScopeError({ + filename: result, + root: root + }); } return result; |