[PR #14828] [MERGED] middleware: handle non-JSON error responses gracefully #14862

Closed
opened 2026-04-13 01:04:16 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ollama/ollama/pull/14828
Author: @BruceMacD
Created: 3/13/2026
Status: Merged
Merged: 3/13/2026
Merged by: @BruceMacD

Base: mainHead: brucemacd/cloud-proxy-err-parse


📝 Commits (1)

  • ea3e36b middleware: handle non-JSON error responses gracefully

📊 Changes

3 files changed (+10 additions, -9 deletions)

View changed files

📝 middleware/anthropic.go (+4 -3)
📝 middleware/openai.go (+5 -5)
📝 middleware/openai_test.go (+1 -1)

📄 Description

writeError in both OpenAI and Anthropic middleware writers would return a raw json.SyntaxError when the error payload wasn't valid JSON (e.g. "invalid character 'e' looking for beginning of value"). Fall back to using the raw bytes as the error message instead.

Also use the actual HTTP status code rather than hardcoding 500, so error types map correctly

Found from #14827


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ollama/ollama/pull/14828 **Author:** [@BruceMacD](https://github.com/BruceMacD) **Created:** 3/13/2026 **Status:** ✅ Merged **Merged:** 3/13/2026 **Merged by:** [@BruceMacD](https://github.com/BruceMacD) **Base:** `main` ← **Head:** `brucemacd/cloud-proxy-err-parse` --- ### 📝 Commits (1) - [`ea3e36b`](https://github.com/ollama/ollama/commit/ea3e36be7c125a03a03156f7c5c5aaaa6cd25ab0) middleware: handle non-JSON error responses gracefully ### 📊 Changes **3 files changed** (+10 additions, -9 deletions) <details> <summary>View changed files</summary> 📝 `middleware/anthropic.go` (+4 -3) 📝 `middleware/openai.go` (+5 -5) 📝 `middleware/openai_test.go` (+1 -1) </details> ### 📄 Description writeError in both OpenAI and Anthropic middleware writers would return a raw json.SyntaxError when the error payload wasn't valid JSON (e.g. "invalid character 'e' looking for beginning of value"). Fall back to using the raw bytes as the error message instead. Also use the actual HTTP status code rather than hardcoding 500, so error types map correctly Found from #14827 --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-04-13 01:04:16 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/ollama#14862