diff --git a/react-packager/src/DependencyResolver/haste/DependencyGraph/index.js b/react-packager/src/DependencyResolver/haste/DependencyGraph/index.js index adb01282..f517236d 100644 --- a/react-packager/src/DependencyResolver/haste/DependencyGraph/index.js +++ b/react-packager/src/DependencyResolver/haste/DependencyGraph/index.js @@ -86,7 +86,11 @@ DependecyGraph.prototype.load = function() { DependecyGraph.prototype.getOrderedDependencies = function(entryPath) { var absolutePath = this._getAbsolutePath(entryPath); if (absolutePath == null) { - throw new Error('Cannot find entry file in any of the roots: ' + entryPath); + throw new NotFoundError( + 'Cannot find entry file %s in any of the roots: %j', + entryPath, + this._roots + ); } var module = this._graph[absolutePath]; @@ -664,4 +668,15 @@ function buildAssetMap(roots, exts) { return search(); } +function NotFoundError() { + Error.call(this); + Error.captureStackTrace(this, this.constructor); + var msg = util.format.apply(util, arguments); + this.message = msg; + this.type = this.name = 'NotFoundError'; + this.status = 404; +} + +NotFoundError.__proto__ = Error.prototype; + module.exports = DependecyGraph; diff --git a/react-packager/src/Server/index.js b/react-packager/src/Server/index.js index f40ebeea..ad417de1 100644 --- a/react-packager/src/Server/index.js +++ b/react-packager/src/Server/index.js @@ -281,11 +281,11 @@ function getBoolOptionFromQuery(query, opt, defaultVal) { } function handleError(res, error) { - res.writeHead(500, { + res.writeHead(error.status || 500, { 'Content-Type': 'application/json; charset=UTF-8', }); - if (error.type === 'TransformError') { + if (error.type === 'TransformError' || error.type === 'NotFoundError') { res.end(JSON.stringify(error)); } else { console.error(error.stack || error);