fix(codex): format reset credit API errors (#3778)
This commit is contained in:
@@ -21,6 +21,13 @@ function toIsoDate(value) {
|
|||||||
return Number.isFinite(time) ? date.toISOString() : null;
|
return Number.isFinite(time) ? date.toISOString() : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function errorMessage(value, fallback) {
|
||||||
|
if (!value) return fallback;
|
||||||
|
if (typeof value === "string") return value;
|
||||||
|
if (typeof value.message === "string") return value.message;
|
||||||
|
return JSON.stringify(value);
|
||||||
|
}
|
||||||
|
|
||||||
function getCodexAccountId(providerSpecificData) {
|
function getCodexAccountId(providerSpecificData) {
|
||||||
return providerSpecificData?.workspaceId || providerSpecificData?.accountId || providerSpecificData?.chatgptAccountId || null;
|
return providerSpecificData?.workspaceId || providerSpecificData?.accountId || providerSpecificData?.chatgptAccountId || null;
|
||||||
}
|
}
|
||||||
@@ -162,7 +169,7 @@ export async function getCodexRateLimitResetCredits(accessToken, proxyOptions =
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
const message = data?.message || data?.error || data?.detail || `Codex reset credits API unavailable (${response.status}).`;
|
const message = errorMessage(data?.message || data?.error || data?.detail, `Codex reset credits API unavailable (${response.status}).`);
|
||||||
throw new Error(message);
|
throw new Error(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -91,6 +91,17 @@ describe("Codex reset credits", () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("surfaces structured upstream errors as readable messages", async () => {
|
||||||
|
mocks.proxyAwareFetch.mockResolvedValue({
|
||||||
|
ok: false,
|
||||||
|
status: 403,
|
||||||
|
json: async () => ({ error: { message: "Reset credits are unavailable for this account" } }),
|
||||||
|
});
|
||||||
|
|
||||||
|
const { getCodexRateLimitResetCredits } = await import("../../open-sse/services/usage/codex.js");
|
||||||
|
await expect(getCodexRateLimitResetCredits("token")).rejects.toThrow("Reset credits are unavailable for this account");
|
||||||
|
});
|
||||||
|
|
||||||
it("GET refreshes OAuth credentials before returning reset credit details", async () => {
|
it("GET refreshes OAuth credentials before returning reset credit details", async () => {
|
||||||
const connection = {
|
const connection = {
|
||||||
id: "conn_1",
|
id: "conn_1",
|
||||||
|
|||||||
Reference in New Issue
Block a user