Skip to content

Conversation

xiaohui-zhangxh
Copy link

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.

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