小飞侠接口调通测试

This commit is contained in:
2026-07-06 17:07:35 +08:00
parent 3625f037d0
commit 4e18763968
8 changed files with 271 additions and 31 deletions
@@ -29,7 +29,7 @@ export class CourierConfigService {
provider,
xiaofeixia: {
apiUrl:
this.config.get<string>('XIAOFEIXIA_API_URL') ??
this.config.get<string>('XIAOFEIXIA_API_URL')?.trim() ||
'https://beta.51xiaoju.cn/app/api/interface.do',
appId: this.config.get<string>('XIAOFEIXIA_APP_ID') || undefined,
mchId: this.config.get<string>('XIAOFEIXIA_MCH_ID') ?? '',
@@ -66,7 +66,22 @@ export class XiaofeixiaClient {
);
}
const payload = (await response.json()) as XiaofeixiaApiResponse<T>;
const rawText = await response.text();
let payload: XiaofeixiaApiResponse<T>;
try {
payload = rawText ? (JSON.parse(rawText) as XiaofeixiaApiResponse<T>) : (null as unknown as XiaofeixiaApiResponse<T>);
} catch {
throw new CourierApiError(
`小飞侠响应非 JSONHTTP ${response.status}: ${rawText.slice(0, 200) || '(空)'}`,
'200000',
'XIAOFEIXIA',
rawText,
);
}
if (!payload) {
throw new CourierApiError('小飞侠返回空响应', '200000', 'XIAOFEIXIA');
}
if (payload.code !== XIAOFEIXIA_SUCCESS_CODE) {
throw new CourierApiError(