chore: utils and type definition

This commit is contained in:
yangsy
2025-08-29 11:41:01 +08:00
parent d948c96047
commit 73776c1fd1
3 changed files with 44 additions and 4 deletions

View File

@@ -48,15 +48,20 @@ export class Request {
return this.instance;
}
get<T>(url: string, option?: AxiosRequestConfig): Promise<Response<T>> {
const reqConfig = option ?? {};
get<T>(url: string, option?: AxiosRequestConfig & { retRaw?: boolean }): Promise<Response<T>> {
const { retRaw, ...reqConfig } = option ?? {};
return new Promise((resolve) => {
this.instance
.get<Result<T>>(url, {
.get(url, {
...reqConfig,
})
.then((res) => {
resolve([null, res.data.data, res.data]);
if (retRaw) {
resolve([null, res.data as T, null]);
} else {
const resData = res.data as Result<T>;
resolve([null, resData.data, resData]);
}
})
.catch((err) => {
resolve([err as AxiosError, null, null]);