/
axe
/
pet2
Обзор
Документация
Войти
/
axe
/
pet2
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
main
public/api.js
23 строки
688 B
gusen
initial commit
09 июн 2026, 22:01
09 июн 2026, 22:01
7bf5434
Код
Авторство
О чём код?
export const api = async (url, options = {}) => { const token = localStorage.getItem('token'); const headers = { 'Content-Type': 'application/json', ...options.headers }; if (token) { headers['Authorization'] = `Bearer ${token}`; } const response = await fetch(url, { ...options, headers }); if (response.status === 401 || response.status === 403) { logout(); throw new Error('Сессия истекла, войдите снова'); } const data = await response.json(); if (!response.ok) { throw new Error(data.error || 'Ошибка запроса'); } return data; };