Skip to content

Conversation

@Pratham-Mishra04
Copy link
Collaborator

Summary

Improved error handling for HTML responses by returning the full HTML body instead of attempting to extract specific error messages.

Changes

  • Modified error handling in multiple provider files to return the raw HTML body as the error message
  • Kept the ExtractHTMLErrorMessage function but marked it as unused for potential future use
  • This change affects Mistral, OpenAI, and Vertex providers, as well as the common provider utilities

Type of change

  • Bug fix
  • Feature
  • Refactor
  • Documentation
  • Chore/CI

Affected areas

  • Core (Go)
  • Transports (HTTP)
  • Providers/Integrations
  • Plugins
  • UI (Next.js)
  • Docs

How to test

Test error scenarios where providers return HTML responses:

# Core/Transports
go version
go test ./...

Breaking changes

  • Yes
  • No

Security considerations

The change now returns full HTML responses in error messages, which could potentially include more information than before, but this is necessary for proper debugging of provider errors.

Checklist

  • I added/updated tests where appropriate
  • I verified builds succeed (Go and UI)

@github-actions
Copy link
Contributor

🧪 Test Suite Available

This PR can be tested by a repository admin.

Run tests for PR #1128

Copy link
Collaborator Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 18, 2025

📝 Walkthrough

Summary by CodeRabbit

Release Notes

  • Bug Fixes

    • Standardized error handling for transcription provider responses, improving error message clarity when services return unexpected HTML responses instead of expected data.
  • Style

    • Updated text styling and layout spacing in the API Keys management interface.

✏️ Tip: You can customize this high-level summary in your review settings.

Walkthrough

Error handling for HTML responses was changed: providers now set a fixed HTML-marker message (ErrProviderResponseHTML) and attach the raw response body as the error value instead of calling ExtractHTMLErrorMessage(). The ExtractHTMLErrorMessage function is preserved but marked UNUSED in utils.

Changes

Cohort / File(s) Summary
Provider HTML error handling
core/providers/mistral/mistral.go, core/providers/openai/openai.go, core/providers/vertex/errors.go
Replaced calls that parsed HTML error messages with a fixed message (schemas.ErrProviderResponseHTML) and attached the raw response body as an error (e.g., errors.New(string(body)) or string(copiedResponseBody)). Status codes and non-HTML paths unchanged.
Provider utils — HTML handling & legacy function
core/providers/utils/utils.go
When JSON/unmarshal fails and response appears to be HTML, now set the message to ErrProviderResponseHTML and attach the raw decoded body as the error. ExtractHTMLErrorMessage() remains defined but is marked UNUSED and no longer invoked.
UI — styling and minor prop change
ui/app/_fallbacks/enterprise/components/api-keys/APIKeysView.tsx
Cosmetic class-name reorderings and text color updates (text-gray-600text-muted-foreground), small wording/formatting tweaks, and ContactUsView invocation updated to include readmeLink prop (leading-space removal in className). No API signatures changed.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20–30 minutes

  • Review provider error paths to confirm uniform use of ErrProviderResponseHTML and consistent construction of the attached error (string vs. errors.New).
  • Check any logging/monitoring that may rely on previously parsed HTML messages.
  • Validate there are no inadvertent information leaks from returning raw HTML bodies.
  • Verify UI prop addition (readmeLink) is intended and does not break consumers.

Poem

I nibble bytes of HTML by moonlight, 🐇
No parsed crumbs — I give the whole bite.
A marker says "HTML" — the body I tuck,
The old extractor sleeps, but waits for luck.
Hop, patch, and ship — a small, tidy delight. ✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: returning raw HTML in error responses instead of extracting messages, which aligns with the actual modifications across all affected provider files.
Description check ✅ Passed The description covers the main points: summary of the change, specific modifications made, type of change selected, affected areas checked, testing instructions provided, and security considerations noted. However, the 'Screenshots/Recordings' and 'How to test' sections lack detail for the UI changes mentioned in the raw summary.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch 12-18-chore_send_back_full_html_instead

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

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
core/providers/utils/utils.go (1)

593-664: Note: Unused function retained for potential future use.

The ExtractHTMLErrorMessage function is now marked as unused but preserved with its full implementation. While the comment indicates it "could be useful in the future," consider:

  1. If there's a concrete plan to use this function (e.g., making HTML extraction optional via configuration), the retention is reasonable
  2. If the need is speculative, removing it and relying on git history might reduce maintenance burden
  3. The function has good ReDoS protection with maxBodySize limit, so it's safe if re-introduced later
📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 628fb20 and cc46374.

📒 Files selected for processing (4)
  • core/providers/mistral/mistral.go (1 hunks)
  • core/providers/openai/openai.go (1 hunks)
  • core/providers/utils/utils.go (3 hunks)
  • core/providers/vertex/errors.go (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**

⚙️ CodeRabbit configuration file

always check the stack if there is one for the current PR. do not give localized reviews for the PR, always see all changes in the light of the whole stack of PRs (if there is a stack, if there is no stack you can continue to make localized suggestions/reviews)

Files:

  • core/providers/utils/utils.go
  • core/providers/openai/openai.go
  • core/providers/mistral/mistral.go
  • core/providers/vertex/errors.go
🧠 Learnings (3)
📚 Learning: 2025-12-09T17:07:42.007Z
Learnt from: qwerty-dvorak
Repo: maximhq/bifrost PR: 1006
File: core/schemas/account.go:9-18
Timestamp: 2025-12-09T17:07:42.007Z
Learning: In core/schemas/account.go, the HuggingFaceKeyConfig field within the Key struct is currently unused and reserved for future Hugging Face inference endpoint deployments. Do not flag this field as missing from OpenAPI documentation or require its presence in the API spec until the feature is actively implemented and used. When the feature is added, update the OpenAPI docs accordingly; otherwise, treat this field as non-breaking and not part of the current API surface.

Applied to files:

  • core/providers/utils/utils.go
  • core/providers/openai/openai.go
  • core/providers/mistral/mistral.go
  • core/providers/vertex/errors.go
📚 Learning: 2025-12-11T11:58:25.307Z
Learnt from: Pratham-Mishra04
Repo: maximhq/bifrost PR: 1000
File: core/providers/openai/responses.go:42-84
Timestamp: 2025-12-11T11:58:25.307Z
Learning: In core/providers/openai/responses.go (and related OpenAI response handling), document and enforce the API format constraint: if ResponsesReasoning != nil and the response contains content blocks, all content blocks should be treated as reasoning blocks by default. Implement type guards or parsing logic accordingly, and add unit tests to verify that when ResponsesReasoning is non-nil, content blocks are labeled as reasoning blocks. Include clear comments in the code explaining the rationale and ensure downstream consumers rely on this behavior.

Applied to files:

  • core/providers/openai/openai.go
📚 Learning: 2025-12-14T14:43:30.902Z
Learnt from: Radheshg04
Repo: maximhq/bifrost PR: 980
File: core/providers/openai/images.go:10-22
Timestamp: 2025-12-14T14:43:30.902Z
Learning: Enforce the OpenAI image generation SSE event type values across the OpenAI image flow in the repository: use "image_generation.partial_image" for partial chunks, "image_generation.completed" for the final result, and "error" for errors. Apply this consistently in schemas, constants, tests, accumulator routing, and UI code within core/providers/openai (and related Go files) to ensure uniform event typing and avoid mismatches.

Applied to files:

  • core/providers/openai/openai.go
🔇 Additional comments (4)
core/providers/vertex/errors.go (1)

55-71: LGTM! Raw HTML error responses now returned for better debugging.

The change to return the full HTML body as the error message (instead of attempting to extract a specific message) improves debugging capabilities for provider errors. The implementation correctly handles status codes and metadata.

Note: HTML error pages from providers can be verbose, but this trade-off is acceptable for debugging purposes as noted in the PR description.

core/providers/mistral/mistral.go (1)

322-332: LGTM! Consistent HTML error handling in transcription.

The change to return the raw HTML response body as the error message is consistent with the PR's approach across all providers. The error structure is correctly populated and uses the copied response body appropriately.

core/providers/openai/openai.go (1)

2006-2017: LGTM! Consistent HTML error handling implementation.

The change to return the full HTML response body aligns with the PR's objective to improve debugging by providing complete error information from providers. The error structure and response handling are correct.

core/providers/utils/utils.go (1)

359-367: LGTM! Consistent raw HTML error handling in utility function.

The change to return the full decoded HTML body as the error message is consistent with the changes across all provider implementations. This provides better debugging information when providers return HTML error pages.

@Pratham-Mishra04 Pratham-Mishra04 force-pushed the 12-18-chore_send_back_full_html_instead branch from cc46374 to 5157d2a Compare December 18, 2025 22:05
@Pratham-Mishra04 Pratham-Mishra04 force-pushed the 12-18-chore_send_back_full_html_instead branch from 5157d2a to 511efc8 Compare December 18, 2025 22:07
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
ui/app/_fallbacks/enterprise/components/api-keys/APIKeysView.tsx (1)

53-111: These UI styling changes appear unrelated to the PR's stated objective.

The PR objective describes fixing error handling for HTML responses in Go providers, but this file contains only React UI styling updates (text color tokens, className ordering, and minor wording adjustments).

Per the coding guidelines to "always see all changes in the light of the whole stack of PRs," these changes may belong to a different PR in the stack. Please verify:

  1. Are these changes intended for a separate PR in the stack?
  2. If they belong in this PR, the PR description should be updated to reflect UI styling changes.

Technical assessment of the changes:
The styling updates themselves are fine—migrating from text-gray-600 to text-muted-foreground promotes design token consistency, and the readmeLink prop is correctly used (ContactUsView already accepts this prop per the codebase).

🧹 Nitpick comments (1)
core/providers/vertex/errors.go (1)

56-72: LGTM! HTML error handling aligns with PR objectives.

The change correctly implements the new pattern of returning raw HTML responses with a fixed message constant. This provides better debugging information and maintains consistency with error handling in other provider files (Mistral, OpenAI).

The implementation properly:

  • Uses the ErrProviderResponseHTML constant for the message
  • Wraps the raw HTML body as an error for full context
  • Preserves the error structure with status code and extra fields
💡 Optional: Consider HTML response size limits

For edge cases where providers return very large HTML error pages, you might want to consider truncating the HTML body to prevent excessive memory usage or log bloat:

const maxHTMLErrorBodySize = 10 * 1024 // 10KB

htmlBody := string(decodedBody)
if len(htmlBody) > maxHTMLErrorBodySize {
    htmlBody = htmlBody[:maxHTMLErrorBodySize] + "... (truncated)"
}
Error: errors.New(htmlBody),

This is purely optional and only relevant if you observe issues with large HTML error responses in practice.

📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between cc46374 and 511efc8.

📒 Files selected for processing (5)
  • core/providers/mistral/mistral.go (1 hunks)
  • core/providers/openai/openai.go (1 hunks)
  • core/providers/utils/utils.go (3 hunks)
  • core/providers/vertex/errors.go (2 hunks)
  • ui/app/_fallbacks/enterprise/components/api-keys/APIKeysView.tsx (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
  • core/providers/utils/utils.go
  • core/providers/mistral/mistral.go
  • core/providers/openai/openai.go
🧰 Additional context used
📓 Path-based instructions (1)
**

⚙️ CodeRabbit configuration file

always check the stack if there is one for the current PR. do not give localized reviews for the PR, always see all changes in the light of the whole stack of PRs (if there is a stack, if there is no stack you can continue to make localized suggestions/reviews)

Files:

  • core/providers/vertex/errors.go
  • ui/app/_fallbacks/enterprise/components/api-keys/APIKeysView.tsx
🧠 Learnings (1)
📚 Learning: 2025-12-09T17:07:42.007Z
Learnt from: qwerty-dvorak
Repo: maximhq/bifrost PR: 1006
File: core/schemas/account.go:9-18
Timestamp: 2025-12-09T17:07:42.007Z
Learning: In core/schemas/account.go, the HuggingFaceKeyConfig field within the Key struct is currently unused and reserved for future Hugging Face inference endpoint deployments. Do not flag this field as missing from OpenAPI documentation or require its presence in the API spec until the feature is actively implemented and used. When the feature is added, update the OpenAPI docs accordingly; otherwise, treat this field as non-breaking and not part of the current API surface.

Applied to files:

  • core/providers/vertex/errors.go
🧬 Code graph analysis (2)
core/providers/vertex/errors.go (1)
core/schemas/provider.go (1)
  • ErrProviderResponseHTML (32-32)
ui/app/_fallbacks/enterprise/components/api-keys/APIKeysView.tsx (1)
ui/app/_fallbacks/enterprise/components/views/contactUsView.tsx (1)
  • ContactUsView (16-47)
🔇 Additional comments (1)
core/providers/vertex/errors.go (1)

4-4: LGTM! Import is necessary and correctly placed.

The addition of the standard errors package is required for the errors.New() call on line 62 and follows proper import conventions.

@akshaydeo akshaydeo merged commit d072fac into main Dec 19, 2025
9 checks passed
@akshaydeo akshaydeo deleted the 12-18-chore_send_back_full_html_instead branch December 19, 2025 08:08
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.

3 participants