[JSAppServer] Don't keep track of not found packages

This commit is contained in:
Martín Bigio 2015-08-06 11:33:46 -07:00
parent 327f84b967
commit aefdf82cdc
1 changed files with 27 additions and 26 deletions

View File

@ -372,12 +372,36 @@ Server.prototype.processRequest = function(req, res, next) {
Activity.endEvent(startReqEventId);
}
},
function(error) {
handleError(res, error);
}
this._handleError.bind(this, res, optionsJson)
).done();
};
Server.prototype._handleError = function(res, packageID, error) {
res.writeHead(error.status || 500, {
'Content-Type': 'application/json; charset=UTF-8',
});
if (error.type === 'TransformError' || error.type === 'NotFoundError') {
error.errors = [{
description: error.description,
filename: error.filename,
lineNumber: error.lineNumber,
}];
res.end(JSON.stringify(error));
if (error.type === 'NotFoundError') {
delete this._packages[packageID];
}
} else {
console.error(error.stack || error);
res.end(JSON.stringify({
type: 'InternalError',
message: 'react-packager has encountered an internal error, ' +
'please check your terminal error output for more details',
}));
}
};
function getOptionsFromUrl(reqUrl) {
// `true` to parse the query param as an object.
var urlObj = url.parse(reqUrl, true);
@ -417,26 +441,3 @@ function getBoolOptionFromQuery(query, opt, defaultVal) {
return query[opt] === 'true' || query[opt] === '1';
}
function handleError(res, error) {
res.writeHead(error.status || 500, {
'Content-Type': 'application/json; charset=UTF-8',
});
if (error.type === 'TransformError' || error.type === 'NotFoundError') {
error.errors = [{
description: error.description,
filename: error.filename,
lineNumber: error.lineNumber,
}];
console.error(error);
res.end(JSON.stringify(error));
} else {
console.error(error.stack || error);
res.end(JSON.stringify({
type: 'InternalError',
message: 'react-packager has encountered an internal error, ' +
'please check your terminal error output for more details',
}));
}
}