@ciwergrp/nuxid 1.8.0 → 1.9.0
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/module.json
CHANGED
|
@@ -20,10 +20,23 @@ export interface CursorFetchOptions<TRequest extends NitroFetchRequest = NitroFe
|
|
|
20
20
|
cursorParam?: string;
|
|
21
21
|
query?: Record<string, any>;
|
|
22
22
|
}
|
|
23
|
+
export interface FetchError<TData = any> {
|
|
24
|
+
statusCode: number | undefined;
|
|
25
|
+
statusMessage: string | undefined;
|
|
26
|
+
_data: TData | undefined;
|
|
27
|
+
}
|
|
23
28
|
export declare function useCursorHttp<T extends Record<string, any> = any, TResponse extends APIResponseCursor<T> = APIResponseCursor<T>, TRequest extends NitroFetchRequest = NitroFetchRequest>(url: TRequest, options?: CursorFetchOptions<TRequest>): Promise<{
|
|
24
29
|
data: import("vue").Ref<TResponse | undefined, TResponse | undefined>;
|
|
25
30
|
loading: Readonly<import("vue").Ref<boolean, boolean>>;
|
|
26
|
-
error: Readonly<import("vue").Ref<
|
|
31
|
+
error: Readonly<import("vue").Ref<{
|
|
32
|
+
readonly statusCode: number | undefined;
|
|
33
|
+
readonly statusMessage: string | undefined;
|
|
34
|
+
readonly _data: any;
|
|
35
|
+
} | null, {
|
|
36
|
+
readonly statusCode: number | undefined;
|
|
37
|
+
readonly statusMessage: string | undefined;
|
|
38
|
+
readonly _data: any;
|
|
39
|
+
} | null>>;
|
|
27
40
|
hasNextPage: Readonly<import("vue").Ref<boolean, boolean>>;
|
|
28
41
|
isLoadMoreTriggered: Readonly<import("vue").Ref<boolean, boolean>>;
|
|
29
42
|
loadMore: () => Promise<void>;
|
|
@@ -36,6 +36,20 @@ export async function useCursorHttp(url, options) {
|
|
|
36
36
|
}
|
|
37
37
|
return unwrapped;
|
|
38
38
|
}
|
|
39
|
+
function normalizeFetchError(e) {
|
|
40
|
+
if (e && typeof e === "object") {
|
|
41
|
+
const cast = e;
|
|
42
|
+
return {
|
|
43
|
+
statusCode: typeof cast.statusCode === "number" ? cast.statusCode : void 0,
|
|
44
|
+
statusMessage: typeof cast.statusMessage === "string" ? cast.statusMessage : cast.message ?? void 0,
|
|
45
|
+
_data: cast.data
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
if (typeof e === "string") {
|
|
49
|
+
return { statusCode: void 0, statusMessage: e, _data: void 0 };
|
|
50
|
+
}
|
|
51
|
+
return { statusCode: void 0, statusMessage: "Unknown error", _data: void 0 };
|
|
52
|
+
}
|
|
39
53
|
const {
|
|
40
54
|
lazy = false,
|
|
41
55
|
immediate = true,
|
|
@@ -102,7 +116,7 @@ export async function useCursorHttp(url, options) {
|
|
|
102
116
|
nextCursor.value = normalizeCursorValue(response.meta?.[cursorKey]);
|
|
103
117
|
hasNextPage.value = response.meta?.[hasMoreKey] ?? false;
|
|
104
118
|
} catch (e) {
|
|
105
|
-
error.value = e;
|
|
119
|
+
error.value = normalizeFetchError(e);
|
|
106
120
|
} finally {
|
|
107
121
|
loading.value = false;
|
|
108
122
|
}
|