- 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.
36 lines
811 B
TypeScript
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;
|
|
}
|
|
};
|