mirror of
https://github.com/status-im/metro.git
synced 2025-02-27 18:20:53 +00:00
[react-packager] better error when main file not found
This commit is contained in:
parent
ecfc78f47e
commit
f68c24069e
@ -86,7 +86,11 @@ DependecyGraph.prototype.load = function() {
|
|||||||
DependecyGraph.prototype.getOrderedDependencies = function(entryPath) {
|
DependecyGraph.prototype.getOrderedDependencies = function(entryPath) {
|
||||||
var absolutePath = this._getAbsolutePath(entryPath);
|
var absolutePath = this._getAbsolutePath(entryPath);
|
||||||
if (absolutePath == null) {
|
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];
|
var module = this._graph[absolutePath];
|
||||||
@ -664,4 +668,15 @@ function buildAssetMap(roots, exts) {
|
|||||||
return search();
|
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;
|
module.exports = DependecyGraph;
|
||||||
|
4
react-packager/src/Server/index.js
vendored
4
react-packager/src/Server/index.js
vendored
@ -281,11 +281,11 @@ function getBoolOptionFromQuery(query, opt, defaultVal) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function handleError(res, error) {
|
function handleError(res, error) {
|
||||||
res.writeHead(500, {
|
res.writeHead(error.status || 500, {
|
||||||
'Content-Type': 'application/json; charset=UTF-8',
|
'Content-Type': 'application/json; charset=UTF-8',
|
||||||
});
|
});
|
||||||
|
|
||||||
if (error.type === 'TransformError') {
|
if (error.type === 'TransformError' || error.type === 'NotFoundError') {
|
||||||
res.end(JSON.stringify(error));
|
res.end(JSON.stringify(error));
|
||||||
} else {
|
} else {
|
||||||
console.error(error.stack || error);
|
console.error(error.stack || error);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user