Files
umra-app/utils/makeRequest.ts
Nurmuhammet Allanov 3d9b8601bf Update layout and localization for improved functionality
- Added AsyncStorage and utility functions for future enhancements.
- Commented out ServicesGrid component in HomeScreen for potential redesign.
- Updated English and Russian localization files with new phrases and translations for prayer times and services.
2025-09-01 18:34:22 +05:00

36 lines
811 B
TypeScript

import { BASE_URL } from './api';
export const makeRequest = async <T,>(
endpoint: string,
options?: RequestInit
): Promise<T> => {
const url = new URL(endpoint, BASE_URL).toString();
try {
const response = await fetch(url, options);
console.log(response);
if (!response.ok) {
let errorData;
try {
errorData = await response.json();
} catch (e) {
// Ignore JSON parsing errors if the body is empty
}
const errorMessage =
errorData?.message ||
`Request failed with status ${response.status}`;
throw new Error(errorMessage);
}
if (response.status === 204) {
return null as T;
}
return response.json();
} catch (error) {
console.error('API request error:', error);
throw error;
}
};