Updates
This commit is contained in:
@@ -19,6 +19,7 @@ export default async function clientCrudFetch<
|
||||
method = "GET",
|
||||
apiOrigin,
|
||||
headers,
|
||||
...options
|
||||
}: ClientCrudFetchParams<T, P>) {
|
||||
try {
|
||||
let pathname = basePath || ``;
|
||||
@@ -46,6 +47,7 @@ export default async function clientCrudFetch<
|
||||
method,
|
||||
body,
|
||||
headers,
|
||||
...options,
|
||||
});
|
||||
|
||||
return res;
|
||||
|
||||
+4
-15
@@ -46,26 +46,15 @@ export default async function fetchApi<
|
||||
} else if (typeof options === "object") {
|
||||
try {
|
||||
let fetchData;
|
||||
let fetchOptions: RequestInit = {};
|
||||
|
||||
if (options.body && typeof options.body === "object") {
|
||||
let oldOptionsBody = _.cloneDeep(options.body);
|
||||
options.body = JSON.stringify(oldOptionsBody);
|
||||
fetchOptions.body = JSON.stringify(options.body);
|
||||
}
|
||||
|
||||
if (options.headers) {
|
||||
options.headers = _.merge(options.headers, finalHeaders);
|
||||
|
||||
const finalOptions: any = { ...options };
|
||||
fetchData = await fetch(url, finalOptions);
|
||||
} else {
|
||||
const finalOptions = {
|
||||
...options,
|
||||
headers: finalHeaders,
|
||||
} as RequestInit;
|
||||
|
||||
fetchData = await fetch(url, finalOptions);
|
||||
}
|
||||
fetchOptions.headers = _.merge(finalHeaders, options.headers || {});
|
||||
|
||||
fetchData = await fetch(url, fetchOptions);
|
||||
data = fetchData.json();
|
||||
} catch (error: any) {
|
||||
console.log("FetchAPI error #2:", error.message);
|
||||
|
||||
Reference in New Issue
Block a user