@superflag-sh/cli 0.1.1 → 0.1.2

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/dist/index.js +20 -10
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -148,17 +148,27 @@ async function api(endpoint, options = {}) {
148
148
  const searchParams = new URLSearchParams(params);
149
149
  url += `?${searchParams.toString()}`;
150
150
  }
151
- const response = await fetch(url, {
152
- method,
153
- headers: {
154
- "Content-Type": "application/json",
155
- Authorization: `Bearer ${token}`
156
- },
157
- body: body ? JSON.stringify(body) : undefined
158
- });
159
- const data = await response.json();
151
+ let response;
152
+ try {
153
+ response = await fetch(url, {
154
+ method,
155
+ headers: {
156
+ "Content-Type": "application/json",
157
+ Authorization: `Bearer ${token}`
158
+ },
159
+ body: body ? JSON.stringify(body) : undefined
160
+ });
161
+ } catch (err) {
162
+ throw new ApiError(err instanceof Error ? `Network error: ${err.message}` : "Network error", 0);
163
+ }
164
+ let data;
165
+ try {
166
+ data = await response.json();
167
+ } catch {
168
+ throw new ApiError(`Invalid response from server (${response.status})`, response.status);
169
+ }
160
170
  if (!response.ok) {
161
- throw new ApiError(data.error || "API request failed", response.status);
171
+ throw new ApiError(typeof data.error === "string" ? data.error : "API request failed", response.status);
162
172
  }
163
173
  return data;
164
174
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@superflag-sh/cli",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "CLI for Superflag feature flags",
5
5
  "type": "module",
6
6
  "bin": {