Commit 3756ff6
translator: handle numeric OpenAI
**Description**
Anthropic→OpenAI error translation could fail with an internal 500 when
an OpenAI-compatible upstream returned a structured JSON error where
`error.code` was numeric (e.g. `400`) instead of string. This change
makes the error model tolerant to both representations so upstream 4xx
diagnostics can still be translated and surfaced to Anthropic clients.
- **Schema decoding hardening (`internal/apischema/openai/openai.go`)**
- Added `UnmarshalJSON` for `openai.ErrorType`.
- `error.code` now accepts:
- JSON string (`"code":"400"`)
- JSON number (`"code":400`)
- `null` / omitted
- Numeric values are normalized to the existing internal `*string`
field.
- **Translator regression coverage
(`internal/translator/anthropic_openai_test.go`)**
- Extended `TestAnthropicToOpenAITranslator_ResponseError` with a JSON
error fixture containing numeric `code`.
- Confirms response still maps to Anthropic error envelope with expected
`type` and `message`.
```json
{
"type": "error",
"error": {
"type": "invalid_request_error",
"message": "Bad request",
"param": null,
"code": 400
}
}
```
**Related Issues/PRs (if applicable)**
Fixes envoyproxy#2151
**Special notes for reviewers (if applicable)**
N/A
---------
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: Ignasi Barrera <ignasi@tetrate.io>
Signed-off-by: yxia216 <yxia216@bloomberg.net>error.code in Anthropic→OpenAI error translation (envoyproxy#2161)1 parent 8299d9a commit 3756ff6
2 files changed
Lines changed: 48 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1662 | 1662 | | |
1663 | 1663 | | |
1664 | 1664 | | |
| 1665 | + | |
| 1666 | + | |
| 1667 | + | |
| 1668 | + | |
| 1669 | + | |
| 1670 | + | |
| 1671 | + | |
| 1672 | + | |
| 1673 | + | |
| 1674 | + | |
| 1675 | + | |
| 1676 | + | |
| 1677 | + | |
| 1678 | + | |
| 1679 | + | |
| 1680 | + | |
| 1681 | + | |
| 1682 | + | |
| 1683 | + | |
| 1684 | + | |
| 1685 | + | |
| 1686 | + | |
| 1687 | + | |
| 1688 | + | |
| 1689 | + | |
| 1690 | + | |
| 1691 | + | |
| 1692 | + | |
| 1693 | + | |
| 1694 | + | |
| 1695 | + | |
| 1696 | + | |
| 1697 | + | |
| 1698 | + | |
| 1699 | + | |
| 1700 | + | |
| 1701 | + | |
| 1702 | + | |
| 1703 | + | |
| 1704 | + | |
| 1705 | + | |
1665 | 1706 | | |
1666 | 1707 | | |
1667 | 1708 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
430 | 430 | | |
431 | 431 | | |
432 | 432 | | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
433 | 440 | | |
434 | 441 | | |
435 | 442 | | |
| |||
0 commit comments