refactor: 优化请求封装

- 优化Result接口定义
- 新增响应数据解析逻辑
- 优化错误解析逻辑
This commit is contained in:
yangsy
2025-12-17 13:26:25 +08:00
parent 52ba3add3f
commit 9af76bacbb
28 changed files with 191 additions and 328 deletions
@@ -1,4 +1,5 @@
import { ndmClient, userClient, type MediaServerStatus, type Station } from '@/apis';
import { unwrapResponse } from '@/utils';
export const isMediaServerAliveApi = async (options?: { stationCode?: Station['code']; signal?: AbortSignal }) => {
const { stationCode, signal } = options ?? {};
@@ -6,9 +7,7 @@ export const isMediaServerAliveApi = async (options?: { stationCode?: Station['c
const prefix = stationCode ? `/${stationCode}` : '';
const endpoint = `${prefix}/api/ndm/ndmServiceAvailable/mediaServer/isAlive`;
const resp = await client.get<MediaServerStatus[]>(endpoint, { signal });
const [err, data] = resp;
if (err) throw err;
if (!data) throw new Error(`${data}`);
const data = unwrapResponse(resp);
return data;
};
@@ -18,8 +17,6 @@ export const isSipServerAliveApi = async (options?: { stationCode?: Station['cod
const prefix = stationCode ? `/${stationCode}` : '';
const endpoint = `${prefix}/api/ndm/ndmServiceAvailable/sipServer/isAlive`;
const resp = await client.get<boolean>(endpoint, { signal });
const [err, data] = resp;
if (err) throw err;
if (data === null) throw new Error(`${data}`);
const data = unwrapResponse(resp);
return data;
};