🌱 尝试迁移部分请求

This commit is contained in:
BTMuli
2026-04-07 21:55:18 +08:00
parent 4b500f6169
commit 211a992022
5 changed files with 85 additions and 48 deletions

View File

@@ -11,6 +11,7 @@ import TGLogger from "./TGLogger.js";
/**
* 请求参数
* @since Beta v0.9.1
* @remarks 请使用 TGHttpsConfig 类型
*/
type TGHttpParams = {
/** 请求方法 */
@@ -30,7 +31,7 @@ type TGHttpParams = {
/**
* 发送请求
* @since Beta v0.9.1
* @typeParam T - 返回数据类型
* @remarks 自 Beta v0.10.0 起弃用,请使用 TGHttps.get() 或 TGHttps.post() 替代
* @param url - 请求地址
* @param options - 请求参数
* @returns 请求结果

View File

@@ -6,8 +6,6 @@
import { type ClientOptions, fetch } from "@tauri-apps/plugin-http";
import JSONBig from "json-bigint";
import TGLogger from "./TGLogger.js";
/**
* 构建 URL 查询字符串
* @since Beta v0.10.0
@@ -165,10 +163,8 @@ async function request<T>(
} else {
httpError = createHttpError(String(error), { cause: error });
}
// 记录错误日志
await TGLogger.Error(`[TGHttps] Request failed: ${httpError.message}`);
// 记录错误日志 TODO根据实际情况调整日志
// await TGLogger.Error(`[TGHttps] Request failed: ${httpError.message}`);
throw httpError;
}
}
@@ -211,6 +207,21 @@ const TGHttps = {
url: string,
config?: TGApp.App.Response.ReqConfParams,
): Promise<TGApp.App.Response.Resp<T>> => request<T>(method, url, config),
/**
* 判断是否为 HTTP 错误
* @since Beta v0.10.0
* @param error - 错误对象
* @returns 是否为 HTTP 错误
*/
isHttpErr: (error: unknown): error is TGApp.App.Response.HttpErr => {
return (
typeof error === "object" &&
error !== null &&
"message" in error &&
typeof error.message === "string"
);
},
};
export default TGHttps;