@hashrytech/quick-components-kit 0.12.7 → 0.12.9
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/CHANGELOG.md +12 -0
- package/dist/modules/api-client.d.ts +2 -1
- package/dist/modules/api-client.js +8 -5
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -55,7 +55,8 @@ export type ErrorHandler = (error: Error) => Promise<void> | void;
|
|
|
55
55
|
*/
|
|
56
56
|
export declare class ApiError extends Error {
|
|
57
57
|
status: number;
|
|
58
|
-
|
|
58
|
+
json?: object;
|
|
59
|
+
constructor(message: string, status: number, json?: object);
|
|
59
60
|
}
|
|
60
61
|
export interface ApiClientEvents {
|
|
61
62
|
onRequest?: (request: Request) => void;
|
|
@@ -6,10 +6,12 @@ import { getProblemDetail } from "./problem-details.js";
|
|
|
6
6
|
*/
|
|
7
7
|
export class ApiError extends Error {
|
|
8
8
|
status;
|
|
9
|
-
|
|
9
|
+
json;
|
|
10
|
+
constructor(message, status, json) {
|
|
10
11
|
super(message);
|
|
11
12
|
this.name = 'ApiError';
|
|
12
13
|
this.status = status;
|
|
14
|
+
this.json = json;
|
|
13
15
|
}
|
|
14
16
|
}
|
|
15
17
|
/**
|
|
@@ -166,7 +168,7 @@ export class ApiClient {
|
|
|
166
168
|
// If response is not JSON, use default status text or log parsing error
|
|
167
169
|
console.warn('API Client: Failed to parse error response as JSON.', e);
|
|
168
170
|
}
|
|
169
|
-
throw new ApiError(errorMessage, response.status);
|
|
171
|
+
throw new ApiError(errorMessage, response.status, errorJson);
|
|
170
172
|
}
|
|
171
173
|
switch (options.responseType) {
|
|
172
174
|
case 'text':
|
|
@@ -197,7 +199,7 @@ export class ApiClient {
|
|
|
197
199
|
*/
|
|
198
200
|
async handleError(error) {
|
|
199
201
|
// Log the error by default
|
|
200
|
-
console.error("API Client encountered an error:", error);
|
|
202
|
+
//console.error("API Client encountered an error:", error);
|
|
201
203
|
// Cast to Error for common properties, or handle specifically
|
|
202
204
|
const err = error instanceof Error ? error : new Error(String(error));
|
|
203
205
|
// Apply registered error handlers
|
|
@@ -232,9 +234,10 @@ export class ApiClient {
|
|
|
232
234
|
catch (error) {
|
|
233
235
|
await this.handleError(error);
|
|
234
236
|
const isApiError = error instanceof ApiError;
|
|
235
|
-
const status = isApiError ? error.status : 503; //
|
|
237
|
+
const status = isApiError ? error.status : 503; // Service Unavailable fallback
|
|
236
238
|
const message = error instanceof Error ? error.message : 'Unexpected error occurred';
|
|
237
|
-
const errorObj = getProblemDetail({ status, title: "Server fetch error", type: "/exceptions/fetch-error/", detail:
|
|
239
|
+
const errorObj = isApiError && error.json ? error.json : getProblemDetail({ status, title: "Server fetch error", type: "/exceptions/fetch-error/", detail: message });
|
|
240
|
+
//const errorObj = status != 503 ? message : getProblemDetail({status, title: "Server fetch error", type: "/exceptions/fetch-error/", detail: "Error fetching data from API", server: message });
|
|
238
241
|
return {
|
|
239
242
|
ok: false,
|
|
240
243
|
status,
|