@acrool/react-fetcher 0.0.10-alpha.1 → 0.0.11-alpha.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.
|
@@ -12,5 +12,5 @@ export interface IFormatResponseErrorReturn {
|
|
|
12
12
|
export type TGetResponseFormatError = (axiosError?: AxiosError) => IFormatResponseErrorReturn;
|
|
13
13
|
export type TCheckIsRefreshTokenRequest = (config: IInternalRequestConfig) => boolean;
|
|
14
14
|
export type TCheckIsErrorResponse = (response: AxiosResponse) => boolean;
|
|
15
|
-
export type TCheckErrorIs401 = (error: IFormatResponseErrorReturn) => boolean;
|
|
16
|
-
export type TOnResponseError = (error: IFormatResponseErrorReturn) => void;
|
|
15
|
+
export type TCheckErrorIs401 = (error: IFormatResponseErrorReturn, httpStatus: string) => boolean;
|
|
16
|
+
export type TOnResponseError = (error: IFormatResponseErrorReturn, httpStatus: string) => void;
|
|
@@ -108,25 +108,36 @@ var ERequestMethod = /* @__PURE__ */ ((ERequestMethod2) => {
|
|
|
108
108
|
ERequestMethod2["PATCH"] = "PATCH";
|
|
109
109
|
return ERequestMethod2;
|
|
110
110
|
})(ERequestMethod || {});
|
|
111
|
-
function
|
|
112
|
-
const n = new FormData(), e2 = (s2,
|
|
113
|
-
for (const [a2,
|
|
114
|
-
const
|
|
115
|
-
if (
|
|
116
|
-
n.append(
|
|
117
|
-
else if (
|
|
118
|
-
const
|
|
119
|
-
n.append(
|
|
120
|
-
} else Array.isArray(
|
|
121
|
-
typeof
|
|
122
|
-
}) : typeof
|
|
111
|
+
function m(r2) {
|
|
112
|
+
const n = new FormData(), e2 = (s2, o = "") => {
|
|
113
|
+
for (const [a2, t2] of Object.entries(s2)) {
|
|
114
|
+
const c = o ? `${o}[${a2}]` : a2;
|
|
115
|
+
if (t2 instanceof File)
|
|
116
|
+
n.append(c, t2);
|
|
117
|
+
else if (t2 instanceof Blob) {
|
|
118
|
+
const i2 = t2.type.split("/")[1] || "bin", f = `${a2}.${i2}`;
|
|
119
|
+
n.append(c, t2, f);
|
|
120
|
+
} else Array.isArray(t2) ? t2.forEach((l2, i2) => {
|
|
121
|
+
typeof l2 == "object" && l2 !== null ? e2(l2, `${c}[${i2}]`) : n.append(`${c}[${i2}]`, l2);
|
|
122
|
+
}) : typeof t2 == "object" && t2 !== null ? e2(t2, c) : t2 != null && n.append(c, t2);
|
|
123
123
|
}
|
|
124
124
|
};
|
|
125
|
-
return e2(
|
|
125
|
+
return e2(r2), n;
|
|
126
|
+
}
|
|
127
|
+
function A(r2) {
|
|
128
|
+
const n = new URLSearchParams(), e2 = (s2, o = "") => {
|
|
129
|
+
for (const [a2, t2] of Object.entries(s2)) {
|
|
130
|
+
const c = o ? `${o}[${a2}]` : a2;
|
|
131
|
+
Array.isArray(t2) ? t2.forEach((l2, i2) => {
|
|
132
|
+
typeof l2 == "object" && l2 !== null ? e2(l2, `${c}[${i2}]`) : n.append(`${c}[${i2}]`, String(l2));
|
|
133
|
+
}) : typeof t2 == "object" && t2 !== null ? e2(t2, c) : t2 != null && n.append(c, String(t2));
|
|
134
|
+
}
|
|
135
|
+
};
|
|
136
|
+
return e2(r2), n;
|
|
126
137
|
}
|
|
127
138
|
const getDataWithContentType = (contentType, data = {}) => {
|
|
128
|
-
if (
|
|
129
|
-
if (contentType === ERequestContentType.formUrlDecode) return data;
|
|
139
|
+
if (contentType === ERequestContentType.formData) return m(data);
|
|
140
|
+
if (contentType === ERequestContentType.formUrlDecode) return A(data);
|
|
130
141
|
return JSON.stringify(data);
|
|
131
142
|
};
|
|
132
143
|
const createRestFulFetcher = (axiosInstance, document2, options) => {
|
|
@@ -761,7 +772,7 @@ const isHTMLForm = kindOfTest("HTMLFormElement");
|
|
|
761
772
|
const toCamelCase = (str) => {
|
|
762
773
|
return str.toLowerCase().replace(
|
|
763
774
|
/[-_\s]([a-z\d])(\w*)/g,
|
|
764
|
-
function replacer(
|
|
775
|
+
function replacer(m2, p1, p2) {
|
|
765
776
|
return p1.toUpperCase() + p2;
|
|
766
777
|
}
|
|
767
778
|
);
|
|
@@ -3171,9 +3182,9 @@ const FetcherProvider = ({
|
|
|
3171
3182
|
}
|
|
3172
3183
|
return response;
|
|
3173
3184
|
};
|
|
3174
|
-
const handleOnResponseError = (responseFirstError) => {
|
|
3185
|
+
const handleOnResponseError = (responseFirstError, httpStatus) => {
|
|
3175
3186
|
if (onResponseError) {
|
|
3176
|
-
onResponseError(responseFirstError);
|
|
3187
|
+
onResponseError(responseFirstError, httpStatus);
|
|
3177
3188
|
}
|
|
3178
3189
|
};
|
|
3179
3190
|
const interceptorsResponseError = (axiosError) => {
|
|
@@ -3185,14 +3196,14 @@ const FetcherProvider = ({
|
|
|
3185
3196
|
if (isDebug) u.warning("[FetcherProvider] interceptorsResponseError(2)", { status, responseFirstError });
|
|
3186
3197
|
const isRefresh = originalConfig && checkIsRefreshTokenRequest ? checkIsRefreshTokenRequest(originalConfig) : false;
|
|
3187
3198
|
if (response && originalConfig) {
|
|
3188
|
-
if (status === 401 || checkErrorIs401 && checkErrorIs401(responseFirstError)) {
|
|
3199
|
+
if (status === 401 || checkErrorIs401 && checkErrorIs401(responseFirstError, String(status))) {
|
|
3189
3200
|
const tokens = getTokens();
|
|
3190
3201
|
if (isDebug) u.warning("[FetcherProvider] enter refresh token flow", { refreshToken: tokens == null ? void 0 : tokens.refreshToken });
|
|
3191
3202
|
if (w(tokens == null ? void 0 : tokens.refreshToken) || isRefresh || originalConfig.pendingRequest) {
|
|
3192
3203
|
isTokenRefreshing = false;
|
|
3193
3204
|
if (isDebug) u.warning("[FetcherProvider] no refreshToken/refreshAPI|pendingRequest fail, force logout");
|
|
3194
3205
|
forceLogout();
|
|
3195
|
-
if (originalConfig.ignoreGlobalError !== true) handleOnResponseError(responseFirstError);
|
|
3206
|
+
if (originalConfig.ignoreGlobalError !== true) handleOnResponseError(responseFirstError, String(status));
|
|
3196
3207
|
return Promise.reject(new FetcherException(responseFirstError));
|
|
3197
3208
|
}
|
|
3198
3209
|
if (!isTokenRefreshing) {
|
|
@@ -3211,7 +3222,7 @@ const FetcherProvider = ({
|
|
|
3211
3222
|
});
|
|
3212
3223
|
}
|
|
3213
3224
|
}
|
|
3214
|
-
if (originalConfig.ignoreGlobalError !== true) handleOnResponseError(responseFirstError);
|
|
3225
|
+
if (originalConfig.ignoreGlobalError !== true) handleOnResponseError(responseFirstError, String(status));
|
|
3215
3226
|
return Promise.reject(new FetcherException(responseFirstError));
|
|
3216
3227
|
};
|
|
3217
3228
|
return /* @__PURE__ */ jsxRuntimeExports.jsx(
|