fix: improve error handling on model setup - #1629
Conversation
|
@Benebo7 is attempting to deploy a commit to the Rohan Verma's projects Team on Vercel. A member of the Team first needs to authorize it. |
📝 WalkthroughWalkthroughModel connection error handling now adds a manual model ID hint for discovery failures, classifies API-key-related HTTP 400 errors as authentication failures, and provides expanded guidance for rate-limited verification results. ChangesModel connection error handling
Estimated code review effort: 2 (Simple) | ~10 minutes Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
surfsense_backend/app/services/model_connection_service.py (1)
123-128: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick winFix the rate-limit message wording.
possible insufficient quotas or unavailable modelis grammatically unclear. Use wording such as: “check whether your provider quota is insufficient or the model is unavailable.”🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@surfsense_backend/app/services/model_connection_service.py` around lines 123 - 128, Update the rate-limit message returned by the rate-limit branch in VerifyResult to use grammatically clear wording, specifically directing users to check whether their provider quota is insufficient or the model is unavailable. Preserve the existing status, success flag, and other guidance.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Outside diff comments:
In `@surfsense_backend/app/services/model_connection_service.py`:
- Around line 123-128: Update the rate-limit message returned by the rate-limit
branch in VerifyResult to use grammatically clear wording, specifically
directing users to check whether their provider quota is insufficient or the
model is unavailable. Preserve the existing status, success flag, and other
guidance.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 2de41fbf-9680-48ea-bda9-7d400f6e321d
📒 Files selected for processing (2)
surfsense_backend/app/routes/model_connections_routes.pysurfsense_backend/app/services/model_connection_service.py
|
@Benebo7 Thanks. Can you please reopen this PR on 'dev' branch. |
My bad |
Summary
Improves the error feedback shown to users when setting up a model
connection — both when testing a model and when discovering available
models. Maps common provider failures (bad API key, rate limit) to
clearer, more actionable messages instead of surfacing raw upstream
errors.
Fix
The problem: When a model test or discovery failed, the UI often
surfaced the raw upstream provider error (e.g. a bare 400), which is
hard to interpret and doesn't guide the user toward a fix.
What changed:
model_connection_service.py_model_test_errornow maps a400containing "api key" to aclear
AUTH_FAILEDresult ("Authentication failed. Check yourcredentials and try again.") instead of a generic 400.
unavailable model, not just a transient throttle.
model_connections_routes.pypreview_connection_modelsreturns a friendlier hint("Try typing the model id manually.") when discovery fails, since
the next best action is manual entry.
Testing
error reads as an authentication failure, not a generic 400.
returns 400 with explicit direction
mentions quota / unavailable model.
High-level PR Summary
This PR improves error handling when users set up model connections by mapping common provider failures to clearer, more actionable error messages. When authentication fails with a
400status code mentioning "api key", the system now returns a specific authentication error instead of a generic message. Rate limit errors now include additional context about possible quota issues or unavailable models. The model discovery endpoint also provides a helpful hint to manually enter the model ID when automatic discovery fails.⏱️ Estimated Review Time: 5-15 minutes
💡 Review Order Suggestion
surfsense_backend/app/services/model_connection_service.pysurfsense_backend/app/routes/model_connections_routes.pySummary by CodeRabbit