@superflag-sh/cli 0.1.0 → 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.
- package/dist/index.js +20 -10
- 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
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
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
|
|
171
|
+
throw new ApiError(typeof data.error === "string" ? data.error : "API request failed", response.status);
|
|
162
172
|
}
|
|
163
173
|
return data;
|
|
164
174
|
}
|