Skip to content

Commit 164f732

Browse files
authored
Merge pull request #17 from CortexLM/fix/insufficient-balance-error-message
fix(tui): display user-friendly error for insufficient balance (402)
2 parents a0ac1d8 + fde87bf commit 164f732

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

src/cortex-tui/src/runner/event_loop/streaming.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,26 @@ impl EventLoop {
467467
return;
468468
}
469469

470+
// Check if this is an insufficient balance error (402 Payment Required)
471+
if error_lower.contains("402")
472+
|| error_lower.contains("insufficient_balance")
473+
|| error_lower.contains("insufficient token balance")
474+
|| error_lower.contains("payment required")
475+
{
476+
self.add_system_message(
477+
"Error: Insufficient token balance to continue the conversation.\n\n\
478+
Please recharge your account at: https://app.cortex.foundation\n\n\
479+
Once recharged, you can continue your conversation.",
480+
);
481+
self.app_state
482+
.toasts
483+
.error("Insufficient balance. Please recharge at app.cortex.foundation");
484+
self.stream_controller.reset();
485+
self.streaming_rx = None;
486+
self.streaming_task = None;
487+
return;
488+
}
489+
470490
// Check if this is a rate limit / usage limit error
471491
if error_lower.contains("rate limit")
472492
|| error_lower.contains("usage limit")

0 commit comments

Comments
 (0)