mirror of
https://github.com/wassname/Open-Assistant.git
synced 2026-08-08 11:13:58 +08:00
Refactor fetch and post to use axios
Fix set_label id missing in payload use frontend_message_id pre-commit Refactor api fetcher/poster to axios create lint Remove string literal for path Revert oasst_api_client.ts Fix warning httpStatusCode OasstError optional parameter Refactor remove api base url for local api Lint add blank line
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
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, { arg: data }) => api.post(url, data).then((res) => res.data);
|
||||
|
||||
api.interceptors.response.use(
|
||||
(response) => response,
|
||||
(error) => {
|
||||
throw new OasstError(error.message ?? error, error.error_code);
|
||||
}
|
||||
);
|
||||
|
||||
export default api;
|
||||
@@ -1,8 +0,0 @@
|
||||
import axios from "axios";
|
||||
|
||||
/**
|
||||
* A minimal Axios based fetcher.
|
||||
*/
|
||||
const fetcher = (url) => axios.get(url).then((res) => res.data);
|
||||
|
||||
export default fetcher;
|
||||
@@ -5,7 +5,7 @@ export class OasstError {
|
||||
errorCode: number;
|
||||
httpStatusCode: number;
|
||||
|
||||
constructor(message: string, errorCode: number, httpStatusCode: number) {
|
||||
constructor(message: string, errorCode: number, httpStatusCode?: number) {
|
||||
this.message = message;
|
||||
this.errorCode = errorCode;
|
||||
this.httpStatusCode = httpStatusCode;
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
const poster = (url, { arg }) => {
|
||||
return fetch(url, {
|
||||
method: "POST",
|
||||
body: JSON.stringify(arg),
|
||||
});
|
||||
};
|
||||
|
||||
export default poster;
|
||||
Reference in New Issue
Block a user