This commit is contained in:
2026-09-15 15:20:35 +08:00
parent ecd0317b58
commit 9d6fde286b
7 changed files with 152 additions and 39 deletions
+24
View File
@@ -65,3 +65,27 @@ export async function overseasApiRequest<T>(config: AxiosRequestConfig) {
throw new ApiError(error instanceof Error ? error.message : '海外接口请求失败')
}
}
export async function overseasBlobRequest(config: AxiosRequestConfig) {
try {
const response = await transport.request<Blob>({ ...config, responseType: 'blob' })
return response.data
} catch (error) {
if (error instanceof ApiError) throw error
if (axios.isAxiosError(error)) {
const body = error.response?.data
if (body instanceof Blob && body.type.includes('json')) {
try {
const parsed: unknown = JSON.parse(await body.text())
if (isApiEnvelope(parsed) || isApiFailure(parsed)) {
throw new ApiError(parsed.message, parsed.code, error.response?.status, undefined, parsed.traceId, parsed.requestId)
}
} catch (parseError) {
if (parseError instanceof ApiError) throw parseError
}
}
throw new ApiError(error.code === 'ERR_NETWORK' ? '无法连接海外服务' : error.message, error.code || 'OVERSEAS_HTTP_ERROR', error.response?.status)
}
throw new ApiError(error instanceof Error ? error.message : '海外文件下载失败')
}
}