@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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/pulsar.js +17 -3
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@novacraft-engineering/pulsar-cli",
3
- "version": "1.1.0",
3
+ "version": "1.1.1",
4
4
  "description": "Pulsar OTA release CLI — bundle, hash, and ship React Native updates over-the-air.",
5
5
  "type": "module",
6
6
  "bin": {
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
- const data = text ? JSON.parse(text) : {};
64
- if (!response.ok) die(`${response.status}: ${data.error || text}`);
65
- return data;
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) {