/
githubmirror
/
Open-Assistant
Обзор
Документация
Войти
/
githubmirror
/
Open-Assistant
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
website/src/lib/api.ts
34 строки
1 KB
ruoniw
Add delete function (#3019)
07 май 2023, 12:27
Не верифицирован
07 май 2023, 12:27
9ad4062
Код
Авторство
О чём код?
/* eslint-disable @typescript-eslint/no-explicit-any */ import axios from "axios"; import { OasstError } from "./oasst_api_client"; const headers = { "Content-Type": "application/json", }; const api = axios.create({ headers }); export const get = (url: string) => api.get(url).then((res) => res.data); export const post = (url: string, data?: { arg: any }) => api.post(url, data?.arg).then((res) => res.data); export const del = (url: string) => api.delete(url).then((res) => res.data); export const put = (url: string, data?: { arg: any }) => api.put(url, data?.arg).then((res) => res.data); api.interceptors.response.use( (response) => response, (error) => { const err = error?.response?.data; throw new OasstError({ message: err?.message ?? error.response.data ?? "", errorCode: err?.errorCode, httpStatusCode: error?.response?.httpStatusCode ?? error.response?.status ?? -1, method: err?.config?.method ?? error.config?.method, path: err?.config?.url ?? error.config?.url, }); } ); export default api;