/
TimurIsm
/
OpenEyes
Обзор
Документация
Войти
/
TimurIsm
/
OpenEyes
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
main
front/src/http/articlesAPI.jsx
67 строк
2 KB
TimurIsm
first_commit
16 май 2026, 15:34
16 май 2026, 15:34
4d3f198
Код
Авторство
О чём код?
import { $authHost, $host } from "./index"; const handleApiError = (error) => { if (error.response?.status === 429) { throw new Error('Слишком много запросов. Попробуйте позже.') } throw new Error(error.response?.data?.message || 'Ошибка сервера') } export const fetchArticles = async (page = 1, limit = 9) => { try { const { data } = await $host.get('api/articles', { params: { page, limit, sort: 'id,ASC' } }); return data; } catch (error) { throw handleApiError(error); } }; export const fetchArticlesList = async () => { try { const { data } = await $host.get('api/articles/list'); return data; } catch (error) { throw handleApiError(error); } }; export const fetchArticleById = async (id) => { try { const { data } = await $host.get(`api/articles/${id}`); return data; } catch (error) { throw handleApiError(error); } }; export const createArticle = async (articleData) => { try { const { data } = await $authHost.post('api/articles', articleData); return data; } catch (error) { throw handleApiError(error); } }; export const updateArticle = async (id, articleData) => { try { const { data } = await $authHost.put(`api/articles/${id}`, articleData); return data; } catch (error) { throw handleApiError(error); } }; export const deleteArticle = async (id) => { try { await $authHost.delete(`api/articles/${id}`); } catch (error) { throw handleApiError(error); } };