fix 'not found' case in [node] badge (#1730)

NPM changed the error body,
breaking the not found case

Fix this by checking the status
code instead of relying on
the errror message in the body.
This commit is contained in:
chris48s
2018-06-10 22:17:52 +01:00
committed by GitHub
parent b418235c7f
commit e8980f70e8

View File

@@ -1861,18 +1861,12 @@ cache({
// Using the Accept header because of this bug:
// <https://github.com/npm/npmjs.org/issues/163>
request(apiUrl, { headers: { 'Accept': '*/*' } }, (err, res, buffer) => {
if (err != null) {
badgeData.text[1] = 'inaccessible';
if (checkErrorResponse(badgeData, err, res, 'package not found')) {
sendBadge(format, badgeData);
return;
}
try {
const data = JSON.parse(buffer);
if (data.error === 'not_found') {
badgeData.text[1] = 'package not found';
sendBadge(format, badgeData);
return;
}
let releaseData;
if (scope === undefined) {
releaseData = data;