Skip to content

Commit

Permalink
[JSAppServer] Don't keep track of not found packages
Browse files Browse the repository at this point in the history
  • Loading branch information
martinbigio committed Aug 6, 2015
1 parent 327f84b commit aefdf82
Showing 1 changed file with 27 additions and 26 deletions.
53 changes: 27 additions & 26 deletions packager/react-packager/src/Server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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',
}));
}
}

0 comments on commit aefdf82

Please sign in to comment.