refactor: dedupe provider usage fetch logic and tests

This commit is contained in:
Peter Steinberger
2026-02-19 12:50:55 +00:00
parent 6195660b1a
commit badafdc7b3
16 changed files with 806 additions and 215 deletions

View File

@@ -1,4 +1,4 @@
import { fetchJson } from "./provider-usage.fetch.shared.js";
import { buildUsageHttpErrorSnapshot, fetchJson } from "./provider-usage.fetch.shared.js";
import { clampPercent, PROVIDER_LABELS } from "./provider-usage.shared.js";
import type { ProviderUsageSnapshot, UsageWindow } from "./provider-usage.types.js";
@@ -38,12 +38,10 @@ export async function fetchZaiUsage(
);
if (!res.ok) {
return {
return buildUsageHttpErrorSnapshot({
provider: "zai",
displayName: PROVIDER_LABELS.zai,
windows: [],
error: `HTTP ${res.status}`,
};
status: res.status,
});
}
const data = (await res.json()) as ZaiUsageResponse;