mirror of
https://github.com/wassname/Open-Assistant.git
synced 2026-07-02 17:00:28 +08:00
29 lines
769 B
TypeScript
29 lines
769 B
TypeScript
import axios from "axios";
|
|
|
|
import { OasstError } from "./oasst_api_client";
|
|
|
|
const headers = {
|
|
"Content-Type": "application/json",
|
|
};
|
|
|
|
// Create Axios such that we always send credential cookies along with the
|
|
// request. This allows the Backend services to authenticate the user.
|
|
const api = axios.create({
|
|
headers,
|
|
withCredentials: true,
|
|
});
|
|
|
|
export const get = (url: string) => api.get(url).then((res) => res.data);
|
|
|
|
export const post = (url: string, { arg: data }) => api.post(url, data).then((res) => res.data);
|
|
|
|
api.interceptors.response.use(
|
|
(response) => response,
|
|
(error) => {
|
|
const err = error?.response?.data;
|
|
throw new OasstError(err?.message ?? error, err?.errorCode, error?.response?.httpStatusCode || -1);
|
|
}
|
|
);
|
|
|
|
export default api;
|