typedapi-client-helpers 0.1.14 → 0.1.15
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.cjs +19 -5
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +19 -5
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -180,7 +180,11 @@ async function readResponseBody(response) {
|
|
|
180
180
|
}
|
|
181
181
|
const contentType = response.headers.get("content-type");
|
|
182
182
|
if (contentType?.includes("application/json")) {
|
|
183
|
-
|
|
183
|
+
try {
|
|
184
|
+
return JSON.parse(text);
|
|
185
|
+
} catch {
|
|
186
|
+
return text;
|
|
187
|
+
}
|
|
184
188
|
}
|
|
185
189
|
return text;
|
|
186
190
|
}
|
|
@@ -198,19 +202,29 @@ async function handleApiResponse(call, options) {
|
|
|
198
202
|
await options?.onSuccess?.(result2);
|
|
199
203
|
return result2;
|
|
200
204
|
}
|
|
201
|
-
const errorData = data;
|
|
202
205
|
const result = {
|
|
203
206
|
ok: false,
|
|
204
207
|
status: response.status,
|
|
205
|
-
response:
|
|
206
|
-
error:
|
|
208
|
+
response: void 0,
|
|
209
|
+
error: data
|
|
207
210
|
};
|
|
208
211
|
await options?.onError?.(result);
|
|
209
212
|
return result;
|
|
210
213
|
} catch (error) {
|
|
214
|
+
if (error instanceof Response) {
|
|
215
|
+
const errorData = await readResponseBody(error.clone());
|
|
216
|
+
const result2 = {
|
|
217
|
+
ok: false,
|
|
218
|
+
status: error.status,
|
|
219
|
+
response: void 0,
|
|
220
|
+
error: errorData
|
|
221
|
+
};
|
|
222
|
+
await options?.onError?.(result2);
|
|
223
|
+
return result2;
|
|
224
|
+
}
|
|
211
225
|
const result = {
|
|
212
226
|
ok: false,
|
|
213
|
-
status:
|
|
227
|
+
status: response?.status ?? 0,
|
|
214
228
|
response: void 0,
|
|
215
229
|
error
|
|
216
230
|
};
|
package/dist/index.d.cts
CHANGED
|
@@ -267,7 +267,7 @@ type HandleApiResponseOptions<TResponse> = {
|
|
|
267
267
|
*
|
|
268
268
|
* Successful responses return `{ ok: true, status, response }`. Failed responses and thrown errors return `{ ok: false, status, error }`.
|
|
269
269
|
*/
|
|
270
|
-
declare function handleApiResponse<TResponse, TError>(call: () => Promise<HttpResponse<TResponse, TError>>, options?: HandleApiResponseOptions<TResponse>): Promise<ApiResult<TResponse>>;
|
|
270
|
+
declare function handleApiResponse<TResponse, TError = unknown>(call: () => Promise<HttpResponse<TResponse, TError>>, options?: HandleApiResponseOptions<TResponse>): Promise<ApiResult<TResponse>>;
|
|
271
271
|
|
|
272
272
|
/** Values supported by the generated API SortDirection enum. */
|
|
273
273
|
type ApiSortDirection = "Default" | "Ascending" | "Descending";
|
package/dist/index.d.ts
CHANGED
|
@@ -267,7 +267,7 @@ type HandleApiResponseOptions<TResponse> = {
|
|
|
267
267
|
*
|
|
268
268
|
* Successful responses return `{ ok: true, status, response }`. Failed responses and thrown errors return `{ ok: false, status, error }`.
|
|
269
269
|
*/
|
|
270
|
-
declare function handleApiResponse<TResponse, TError>(call: () => Promise<HttpResponse<TResponse, TError>>, options?: HandleApiResponseOptions<TResponse>): Promise<ApiResult<TResponse>>;
|
|
270
|
+
declare function handleApiResponse<TResponse, TError = unknown>(call: () => Promise<HttpResponse<TResponse, TError>>, options?: HandleApiResponseOptions<TResponse>): Promise<ApiResult<TResponse>>;
|
|
271
271
|
|
|
272
272
|
/** Values supported by the generated API SortDirection enum. */
|
|
273
273
|
type ApiSortDirection = "Default" | "Ascending" | "Descending";
|
package/dist/index.js
CHANGED
|
@@ -147,7 +147,11 @@ async function readResponseBody(response) {
|
|
|
147
147
|
}
|
|
148
148
|
const contentType = response.headers.get("content-type");
|
|
149
149
|
if (contentType?.includes("application/json")) {
|
|
150
|
-
|
|
150
|
+
try {
|
|
151
|
+
return JSON.parse(text);
|
|
152
|
+
} catch {
|
|
153
|
+
return text;
|
|
154
|
+
}
|
|
151
155
|
}
|
|
152
156
|
return text;
|
|
153
157
|
}
|
|
@@ -165,19 +169,29 @@ async function handleApiResponse(call, options) {
|
|
|
165
169
|
await options?.onSuccess?.(result2);
|
|
166
170
|
return result2;
|
|
167
171
|
}
|
|
168
|
-
const errorData = data;
|
|
169
172
|
const result = {
|
|
170
173
|
ok: false,
|
|
171
174
|
status: response.status,
|
|
172
|
-
response:
|
|
173
|
-
error:
|
|
175
|
+
response: void 0,
|
|
176
|
+
error: data
|
|
174
177
|
};
|
|
175
178
|
await options?.onError?.(result);
|
|
176
179
|
return result;
|
|
177
180
|
} catch (error) {
|
|
181
|
+
if (error instanceof Response) {
|
|
182
|
+
const errorData = await readResponseBody(error.clone());
|
|
183
|
+
const result2 = {
|
|
184
|
+
ok: false,
|
|
185
|
+
status: error.status,
|
|
186
|
+
response: void 0,
|
|
187
|
+
error: errorData
|
|
188
|
+
};
|
|
189
|
+
await options?.onError?.(result2);
|
|
190
|
+
return result2;
|
|
191
|
+
}
|
|
178
192
|
const result = {
|
|
179
193
|
ok: false,
|
|
180
|
-
status:
|
|
194
|
+
status: response?.status ?? 0,
|
|
181
195
|
response: void 0,
|
|
182
196
|
error
|
|
183
197
|
};
|