late fee added
This commit is contained in:
+19
-28
@@ -1,4 +1,5 @@
|
||||
import axios, { AxiosRequestConfig, isAxiosError } from "axios";
|
||||
import axios, { AxiosRequestConfig } from "axios";
|
||||
import { Alert, ToastAndroid } from "react-native";
|
||||
import * as Keychain from "react-native-keychain";
|
||||
|
||||
/**
|
||||
@@ -12,16 +13,9 @@ export async function apiCall<T>(
|
||||
url: string,
|
||||
method: "GET" | "POST" | "PUT" | "DELETE" = "GET",
|
||||
data?: any,
|
||||
config?: AxiosRequestConfig
|
||||
): Promise<T | null> {
|
||||
// --- Request Logging ---
|
||||
console.log("--- API Request ---");
|
||||
console.log(`[${method}] ${url}`);
|
||||
if (data) {
|
||||
console.log("Payload:", JSON.stringify(data, null, 2));
|
||||
}
|
||||
console.log("-------------------");
|
||||
|
||||
config?: AxiosRequestConfig,
|
||||
responseErrorMessage?:string
|
||||
): Promise<T | null > {
|
||||
try {
|
||||
// Get saved credentials from Keychain
|
||||
const creds = await Keychain.getGenericPassword();
|
||||
@@ -49,25 +43,22 @@ export async function apiCall<T>(
|
||||
|
||||
return response.data;
|
||||
} catch (error: any) {
|
||||
console.error("--- API Error ---");
|
||||
console.error(`Request Failed: [${method}] ${url}`);
|
||||
|
||||
if (isAxiosError(error)) {
|
||||
if (error.response) {
|
||||
// Server responded with a status other than 2xx
|
||||
console.error(`Status: ${error.response.status}`);
|
||||
console.error("Data:", JSON.stringify(error.response.data, null, 2));
|
||||
console.error("Headers:", JSON.stringify(error.response.headers, null, 2));
|
||||
} else if (error.request) {
|
||||
// Request was made but no response received
|
||||
console.error("No response received. This could be a network issue or CORS problem.");
|
||||
} else {
|
||||
// Something else went wrong while setting up the request
|
||||
console.error("Error setting up request:", error.message);
|
||||
if (error.response) {
|
||||
// Server responded with a status other than 2xx
|
||||
console.error(
|
||||
"API Error:",
|
||||
`Status: ${error.response.status}`,
|
||||
`Data: ${JSON.stringify(error.response.data)}`
|
||||
);
|
||||
if(error.response.status === 400){
|
||||
ToastAndroid.show(error.response.data.message || responseErrorMessage, ToastAndroid.SHORT)
|
||||
}
|
||||
} else if (error.request) {
|
||||
// Request was made but no response received
|
||||
console.error("API Error: No response received", error.request);
|
||||
} else {
|
||||
// Non-Axios error
|
||||
console.error("An unexpected error occurred:", error.message);
|
||||
// Something else went wrong while setting up the request
|
||||
console.error("API Error:", error);
|
||||
}
|
||||
console.error("-----------------");
|
||||
|
||||
|
||||
@@ -19,3 +19,4 @@ export const USER_REQUEST = `${BASE_URL}fund/my-requests`
|
||||
export const GROUP_ALL_MEMBER = `${BASE_URL}fund/group/all/member`
|
||||
export const UPDATE_BANK_URL = `${BASE_URL}user/bank/update`;
|
||||
export const CONTRIBUTE = `${BASE_URL}payments/groups/`;
|
||||
export const TRANSACTION = `${BASE_URL}payments/my-transactions`;
|
||||
|
||||
Reference in New Issue
Block a user