before merge
This commit is contained in:
+22
-2
@@ -12,8 +12,27 @@ export const apiCall = async <R, D = {}>(
|
||||
): Promise<R> => {
|
||||
try {
|
||||
const token: any = store.getState().token.token;
|
||||
|
||||
console.log("url : ", url)
|
||||
console.log("token : ", token)
|
||||
|
||||
// Generate curl command
|
||||
let curlCmd = `curl -X ${method.toUpperCase()} "${url}"`;
|
||||
if (token?.token) curlCmd += ` -H "Authentication: Bearer ${token.token}"`;
|
||||
curlCmd += ` -H "Content-Type: ${contentType || 'application/json'}"`;
|
||||
if (data) {
|
||||
if (contentType === 'multipart/form-data') {
|
||||
curlCmd += ` --form "${JSON.stringify(data).slice(1,-1).replace(/"/g, '\\"')}"`;
|
||||
} else {
|
||||
curlCmd += ` -d '${JSON.stringify(data)}'`;
|
||||
}
|
||||
}
|
||||
if (params) {
|
||||
curlCmd += ` ${Object.entries(params).map(([k,v]) => `-${k}=${v}`).join(' ')}`;
|
||||
}
|
||||
console.log("=== CURL ===");
|
||||
console.log(curlCmd);
|
||||
console.log("============");
|
||||
|
||||
const response = await axios({
|
||||
method,
|
||||
url,
|
||||
@@ -26,7 +45,8 @@ export const apiCall = async <R, D = {}>(
|
||||
'Content-Type': contentType || 'application/json',
|
||||
},
|
||||
});
|
||||
console.log("url : ", url)
|
||||
|
||||
console.log("Api response",response)
|
||||
return response.data;
|
||||
} catch (error: any) {
|
||||
const errorMessage = error?.response?.data?.error;
|
||||
|
||||
Reference in New Issue
Block a user