Clean not found/error requests from nodejs HTTP agent

Differential Revision: D7635421

fbshipit-source-id: 2a825a99ce57857354f17496239a9537bf068bc2
This commit is contained in:
Rafael Oleza 2018-04-16 04:17:51 -07:00 committed by Facebook Github Bot
parent f5e93c6e91
commit 8fcc40edf2
1 changed files with 13 additions and 5 deletions

View File

@ -77,11 +77,16 @@ class HttpStore {
const req = this._module.request(options, res => {
let data = '';
if (res.statusCode === 404) {
resolve(null);
return;
} else if (res.statusCode !== 200) {
reject(new Error('HTTP error: ' + res.statusCode));
if (res.statusCode !== 200) {
// Consume all the data from the response without processing it.
res.resume();
if (res.statusCode === 404) {
resolve(null);
} else {
reject(new Error('HTTP error: ' + res.statusCode));
}
return;
}
@ -135,6 +140,9 @@ class HttpStore {
res.on('end', () => {
resolve();
});
// Consume all the data from the response without processing it.
res.resume();
});
gzip.pipe(req);