Skip to content

Fix: error treatment model setup - #1632

Merged
MODSetter merged 2 commits into
MODSetter:devfrom
Benebo7:fix/error-treatment-model-setup
Jul 26, 2026
Merged

Fix: error treatment model setup#1632
MODSetter merged 2 commits into
MODSetter:devfrom
Benebo7:fix/error-treatment-model-setup

Conversation

@Benebo7

@Benebo7 Benebo7 commented Jul 26, 2026

Copy link
Copy Markdown
Contributor

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_error now maps a 400 containing "api key" to a
      clear AUTH_FAILED result ("Authentication failed. Check your
      credentials and try again.") instead of a generic 400.
    • The rate-limit message now also hints at insufficient quota or an
      unavailable model, not just a transient throttle.
  • model_connections_routes.py

    • preview_connection_models returns a friendlier hint
      ("Try typing the model id manually.") when discovery fails, since
      the next best action is manual entry.

Testing

  1. Set up a model connection with an invalid API key → verify the
    error reads as an authentication failure, not a generic 400.
  2. Using refresh button on model setup for automatic discover on a non-cataloged provider
    returns 400 with explicit direction
  3. Trigger a rate limit (or simulate a 429) → verify the message
    mentions quota / unavailable model.

High-level PR Summary

This PR improves error handling when users set up model connections by mapping common provider failures (invalid API keys, rate limits) to clearer, more actionable error messages. Instead of showing raw upstream errors like bare HTTP 400 responses, the system now provides specific guidance such as checking credentials for authentication failures or manually entering model IDs when automatic discovery fails. The changes enhance the user experience by making error feedback more interpretable and directing users toward concrete next steps.

⏱️ Estimated Review Time: 5-15 minutes

💡 Review Order Suggestion
Order File Path
1 surfsense_backend/app/services/model_connection_service.py
2 surfsense_backend/app/routes/model_connections_routes.py

Need help? Join our Discord

@coderabbitai

coderabbitai Bot commented Jul 26, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: ed6388b5-3639-43d2-9496-c0f9b1a78f47

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@MODSetter
MODSetter merged commit eaa7ea9 into MODSetter:dev Jul 26, 2026
8 of 21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants