Spaces:
Sleeping
Sleeping
Download frontend/src/api/client.js from Caner7/Muhasebe: direct link, hf CLI and curl.
- Browser
- Download file 1.11 kB
-
https://huggingface.co/spaces/Caner7/Muhasebe/resolve/main/frontend/src/api/client.js
- Command line
-
hf download hf://spaces/Caner7/Muhasebe/frontend/src/api/client.js
-
curl -L -o client.js https://huggingface.co/spaces/Caner7/Muhasebe/resolve/main/frontend/src/api/client.js
1.11 kB
| /** Tüm backend çağrıları: JSON, cookie (session) ve isteğe bağlı Bearer token. */ | |
| import { getAuthToken } from "../auth/token.js"; | |
| export async function apiRequest(path, options = {}) { | |
| const token = getAuthToken(); | |
| const response = await fetch(path, { | |
| credentials: "include", | |
| headers: { | |
| "Content-Type": "application/json", | |
| ...(token ? { Authorization: `Bearer ${token}` } : {}), | |
| ...(options.headers || {}), | |
| }, | |
| ...options, | |
| }); | |
| const data = await response.json().catch(() => ({})); | |
| if (!response.ok) { | |
| let msg = "Bir hata olustu"; | |
| const d = data.detail; | |
| if (typeof d === "string") msg = d; | |
| else if (Array.isArray(d)) | |
| msg = d.map((x) => (x && typeof x === "object" && x.msg ? x.msg : String(x))).join(", "); | |
| else if (data.message) msg = data.message; | |
| const err = new Error(msg); | |
| err.status = response.status; | |
| throw err; | |
| } | |
| return data; | |
| } | |
| export function isAuthError(err) { | |
| if (!err) return false; | |
| return ( | |
| err.status === 401 || err.message === "Yetkisiz erisim" || err.message === "Oturum yok" | |
| ); | |
| } | |