@novacraft-engineering/pulsar-cli 1.1.0 → 1.1.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/package.json +1 -1
- package/pulsar.js +17 -3
package/package.json
CHANGED
package/pulsar.js
CHANGED
|
@@ -60,9 +60,23 @@ async function api(pathname, {method = 'GET', body, headers = {}, raw, allowAnon
|
|
|
60
60
|
body: raw ? body : body ? JSON.stringify(body) : undefined,
|
|
61
61
|
});
|
|
62
62
|
const text = await response.text();
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
63
|
+
// Check the status BEFORE parsing: an edge/proxy error (413, 502, 524) returns
|
|
64
|
+
// an HTML page, and parsing that first turned every such failure into an
|
|
65
|
+
// opaque "Unexpected token '<'" SyntaxError instead of the real status.
|
|
66
|
+
if (!response.ok) {
|
|
67
|
+
let detail = text;
|
|
68
|
+
try {
|
|
69
|
+
detail = JSON.parse(text).error || text;
|
|
70
|
+
} catch {
|
|
71
|
+
detail = text.replace(/<[^>]*>/g, ' ').replace(/\s+/g, ' ').trim().slice(0, 300);
|
|
72
|
+
}
|
|
73
|
+
die(`${response.status} ${response.statusText}: ${detail}`);
|
|
74
|
+
}
|
|
75
|
+
try {
|
|
76
|
+
return text ? JSON.parse(text) : {};
|
|
77
|
+
} catch {
|
|
78
|
+
die(`${response.status}: expected JSON, got ${text.slice(0, 200)}`);
|
|
79
|
+
}
|
|
66
80
|
}
|
|
67
81
|
|
|
68
82
|
function die(message) {
|