fix error handling in react native heap capture server middleware
Reviewed By: bnham Differential Revision: D3684092 fbshipit-source-id: 1856fa4c04a173e1df49dfe17ebef09a066447e5
This commit is contained in:
Родитель
e6b850871b
Коммит
c43c80bd7c
|
@ -25,8 +25,12 @@ module.exports = function(req, res, next) {
|
||||||
fs.appendFileSync(preload, req.rawBody);
|
fs.appendFileSync(preload, req.rawBody);
|
||||||
fs.appendFileSync(preload, ';');
|
fs.appendFileSync(preload, ';');
|
||||||
res.end();
|
res.end();
|
||||||
|
const captureDir = path.join(__dirname, 'heapCapture/captures');
|
||||||
|
if (!fs.existsSync(captureDir)) {
|
||||||
|
fs.mkdirSync(captureDir);
|
||||||
|
}
|
||||||
console.log('Packaging Trace');
|
console.log('Packaging Trace');
|
||||||
var captureHtml = path.join(__dirname, 'heapCapture/captures/capture_' + Date.now() + '.html');
|
var captureHtml = captureDir + '/capture_' + Date.now() + '.html';
|
||||||
var capture = fs.createWriteStream(captureHtml);
|
var capture = fs.createWriteStream(captureHtml);
|
||||||
var inliner = spawn(
|
var inliner = spawn(
|
||||||
'inliner',
|
'inliner',
|
||||||
|
@ -35,6 +39,10 @@ module.exports = function(req, res, next) {
|
||||||
stdio: [ process.stdin, 'pipe', process.stderr ],
|
stdio: [ process.stdin, 'pipe', process.stderr ],
|
||||||
});
|
});
|
||||||
inliner.stdout.pipe(capture);
|
inliner.stdout.pipe(capture);
|
||||||
|
inliner.on('error', (err) => {
|
||||||
|
console.error('Error processing heap capture: ' + err.message);
|
||||||
|
console.error('make sure you have installed inliner with \'npm install inliner -g\'');
|
||||||
|
});
|
||||||
inliner.on('exit', (code, signal) => {
|
inliner.on('exit', (code, signal) => {
|
||||||
if (code === 0) {
|
if (code === 0) {
|
||||||
console.log('Heap capture written to: ' + captureHtml);
|
console.log('Heap capture written to: ' + captureHtml);
|
||||||
|
|
Загрузка…
Ссылка в новой задаче