More detailed error output on registry fetch errors

This commit is contained in:
Michael Jackson 2018-07-15 12:38:31 -07:00
parent d05ff65089
commit c464dc3c3e
2 changed files with 22 additions and 3 deletions

View File

@ -3,6 +3,7 @@ const https = require("https");
const gunzip = require("gunzip-maybe");
const tar = require("tar-stream");
const bufferStream = require("./bufferStream");
const agent = require("./registryAgent");
function fetchNpmPackage(packageConfig) {
@ -25,8 +26,17 @@ function fetchNpmPackage(packageConfig) {
if (res.statusCode === 200) {
resolve(res.pipe(gunzip()).pipe(tar.extract()));
} else {
const spec = `${packageConfig.name}@${packageConfig.version}`;
reject(new Error(`Failed to fetch tarball for ${spec}`));
bufferStream(res).then(data => {
const spec = `${packageConfig.name}@${packageConfig.version}`;
const content = data.toString("utf-8");
const error = new Error(
`Failed to fetch tarball for ${spec}\nstatus: ${
res.statusCode
}\ndata: ${content}`
);
reject(error);
});
}
})
.on("error", reject);

View File

@ -37,7 +37,16 @@ function fetchNpmPackageInfo(packageName) {
if (res.statusCode === 200) {
resolve(parseJSON(res));
} else {
reject(new Error(`Failed to fetch info for ${packageName}`));
bufferStream(res).then(data => {
const content = data.toString("utf-8");
const error = new Error(
`Failed to fetch info for ${packageName}\nstatus: ${
res.statusCode
}\ndata: ${content}`
);
reject(error);
});
}
})
.on("error", reject);