first commit

This commit is contained in:
Mateusz Gruszczyński
2026-07-17 15:29:08 +02:00
commit 771494671b
35 changed files with 5020 additions and 0 deletions
+19
View File
@@ -0,0 +1,19 @@
export async function api(path, options = {}) {
const controller = new AbortController();
const timeout = setTimeout(() => controller.abort(), 12000);
try {
const response = await fetch(path, {
...options,
headers: { "content-type": "application/json", ...(options.headers || {}) },
signal: controller.signal,
});
const data = await response.json().catch(() => ({}));
if (!response.ok) throw new Error(data.error || `Błąd ${response.status}`);
return data;
} catch (error) {
if (error.name === "AbortError") throw new Error("Przekroczono czas odpowiedzi serwera");
throw error;
} finally {
clearTimeout(timeout);
}
}