@@ -134,6 +134,16 @@ describe("formatAssistantErrorText", () => {
|
134 | 134 | expect(result).toContain("API provider"); |
135 | 135 | expect(result).toBe(BILLING_ERROR_USER_MESSAGE); |
136 | 136 | }); |
| 137 | +it("returns a friendly billing message for flat JSON insufficient_balance payloads (#74079)", () => { |
| 138 | +const msg = makeAssistantError( |
| 139 | +'{"error":"insufficient_balance","message":"Insufficient MBT balance. Top up or upgrade your subscription to continue.","upgradeUrl":"/settings/billing"}', |
| 140 | +); |
| 141 | +const result = formatAssistantErrorText(msg, { |
| 142 | +provider: "google", |
| 143 | +model: "gemini-3.1-pro-preview", |
| 144 | +}); |
| 145 | +expect(result).toBe(formatBillingErrorMessage("google", "gemini-3.1-pro-preview")); |
| 146 | +}); |
137 | 147 | it("returns a friendly message for rate limit errors", () => { |
138 | 148 | const msg = makeAssistantError("429 rate limit reached"); |
139 | 149 | expect(formatAssistantErrorText(msg)).toContain("rate limit reached"); |
@@ -404,4 +414,13 @@ describe("raw API error payload helpers", () => {
|
404 | 414 | expect(getApiErrorPayloadFingerprint(raw)).toContain("server_error"); |
405 | 415 | expect(getApiErrorPayloadFingerprint(raw)).toContain("req_123"); |
406 | 416 | }); |
| 417 | + |
| 418 | +it("recognizes flat JSON payloads with string error code and message (#74079)", () => { |
| 419 | +const raw = |
| 420 | +'{"error":"insufficient_balance","message":"Insufficient MBT balance. Top up or upgrade your subscription to continue.","upgradeUrl":"/settings/billing"}'; |
| 421 | +expect(isRawApiErrorPayload(raw)).toBe(true); |
| 422 | +expect(formatRawAssistantErrorForUi(raw)).toBe( |
| 423 | +"LLM error insufficient_balance: Insufficient MBT balance. Top up or upgrade your subscription to continue.", |
| 424 | +); |
| 425 | +}); |
407 | 426 | }); |