Gaurav711's picture
feat: NeuralVault 2.0 - Complete Free-Tier Groq & ML Explainability Architecture
62c290b
Raw
History Blame Contribute Delete
731 Bytes
const API_BASE = process.env.REACT_APP_BACKEND_URL || '';
export async function apiCall(endpoint, data, options = {}) {
const { timeout = 30000 } = options;
const controller = new AbortController();
const timer = setTimeout(() => controller.abort(), timeout);
try {
const res = await fetch(`${API_BASE}${endpoint}`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(data),
signal: controller.signal,
});
clearTimeout(timer);
if (!res.ok) throw new Error(`HTTP ${res.status}`);
return await res.json();
} catch (err) {
clearTimeout(timer);
if (err.name === 'AbortError') throw new Error('Request timed out');
throw err;
}
}