some changes in ui
This commit is contained in:
+12
-31
@@ -11,57 +11,38 @@ 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,
|
||||
data,
|
||||
params,
|
||||
// withCredentials: true,
|
||||
// baseURL: Variable.Main_Base,
|
||||
headers: {
|
||||
Authentication: `Bearer ${token?.token}`,
|
||||
'Content-Type': contentType || 'application/json',
|
||||
},
|
||||
});
|
||||
|
||||
console.log("Api response",response)
|
||||
|
||||
return response.data;
|
||||
} catch (error: any) {
|
||||
const errorMessage = error?.response?.data?.error;
|
||||
console.log(errorMessage, '---------------------------api error message');
|
||||
// console.log(error?.response?.data.error, '---------------------------api error message');
|
||||
|
||||
if (error?.response?.status === 401) {
|
||||
if (error?.response?.statusCode === 401) {
|
||||
store.dispatch(setToken({}));
|
||||
return {
|
||||
success: false,
|
||||
message: 'JWT Error - Token expired or malformed',
|
||||
} as R;
|
||||
}
|
||||
const data = {
|
||||
data: {
|
||||
success: false,
|
||||
message: error?.response?.data?.message || 'No Response From Server',
|
||||
}
|
||||
|
||||
return {
|
||||
success: false,
|
||||
message: error?.response?.data?.message || 'No Response From Server',
|
||||
} as R;
|
||||
}
|
||||
|
||||
return data as any
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user