npmguard-cli 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/api.js +5 -1
- package/package.json +1 -1
package/dist/api.js
CHANGED
|
@@ -4,6 +4,10 @@ async function request(url, options) {
|
|
|
4
4
|
const body = await res.text().catch(() => "");
|
|
5
5
|
throw new Error(`HTTP ${res.status}: ${body || res.statusText}`);
|
|
6
6
|
}
|
|
7
|
+
const contentType = res.headers.get("content-type") || "";
|
|
8
|
+
if (!contentType.includes("application/json")) {
|
|
9
|
+
throw new Error(`Expected JSON but got ${contentType || "unknown content type"}`);
|
|
10
|
+
}
|
|
7
11
|
return res.json();
|
|
8
12
|
}
|
|
9
13
|
export async function checkout(apiUrl, packageName, version) {
|
|
@@ -58,7 +62,7 @@ export async function getPackageReport(apiUrl, packageName, version) {
|
|
|
58
62
|
return await request(url);
|
|
59
63
|
}
|
|
60
64
|
catch (err) {
|
|
61
|
-
if (err instanceof Error && err.message.startsWith("HTTP 404")) {
|
|
65
|
+
if (err instanceof Error && (err.message.startsWith("HTTP 404") || err.message.startsWith("Expected JSON"))) {
|
|
62
66
|
return null;
|
|
63
67
|
}
|
|
64
68
|
throw err;
|