Skip to content

Fix Openrouter Error Parser to Handle Detailed Error Messages#431

Merged
crmne merged 4 commits intocrmne:mainfrom
xiaohui-zhangxh:llm/openrouter-parse-detailed-error
Mar 2, 2026
Merged

Fix Openrouter Error Parser to Handle Detailed Error Messages#431
crmne merged 4 commits intocrmne:mainfrom
xiaohui-zhangxh:llm/openrouter-parse-detailed-error

Conversation

@xiaohui-zhangxh
Copy link
Contributor

Fix Openrouter Error Parser to Handle Detailed Error Messages

Problem

Currently, when Openrouter returns detailed error information, the error parser only extracts the generic "Provider returned error" message, losing valuable context from the nested error details.

Solution

Enhanced the Openrouter error parser to combine both the main error message and the detailed error message from metadata when available.

Before:

Error: Provider returned error

After:

Error: Provider returned error - Country, region, or territory not supported

Example Error Response

{
  "error": {
    "message": "Provider returned error",
    "code": 403,
    "metadata": {
      "raw": "{\"error\":{\"code\":\"unsupported_country_region_territory\",\"message\":\"Country, region, or territory not supported\",\"param\":null,\"type\":\"request_forbidden\"}}",
      "provider_name": "OpenAI"
    }
  },
  "user_id": "user_2"
}

Benefits

  • 🔍 Better debugging: Users get specific error details instead of generic messages
  • 🌍 Regional issues: Clearer feedback for geographic restrictions
  • 🛠️ Developer experience: More actionable error information

Type of Change

  • Bug fix (non-breaking change which fixes an issue)

API Changes

  • No API changes

@crmne
Copy link
Owner

crmne commented Sep 25, 2025

Thank you for this.

Has this been tested?

Can you add a test for it?

You could simply change one of the existing tests that mock errors.

@xiaohui-zhangxh
Copy link
Contributor Author

Thank you for this.

Has this been tested?

Can you add a test for it?

You could simply change one of the existing tests that mock errors.

Hi @crmne, thanks for your review. I have added the tests. Could you please take another look?

@crmne crmne force-pushed the llm/openrouter-parse-detailed-error branch from 06c82ec to 9ffb443 Compare March 2, 2026 11:11
@crmne crmne merged commit 18628cc into crmne:main Mar 2, 2026
19 checks passed
@codecov
Copy link

codecov bot commented Mar 2, 2026

Codecov Report

❌ Patch coverage is 75.00000% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 81.27%. Comparing base (ff0b6df) to head (ec87954).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
lib/ruby_llm/providers/openrouter.rb 75.00% 4 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #431      +/-   ##
==========================================
- Coverage   81.29%   81.27%   -0.02%     
==========================================
  Files         116      116              
  Lines        5345     5361      +16     
  Branches     1398     1404       +6     
==========================================
+ Hits         4345     4357      +12     
- Misses       1000     1004       +4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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