Skip to content

Refactor error response handling in proxy plugin#1258

Open
aswmac wants to merge 2 commits into
chimurai:masterfrom
aswmac:master
Open

Refactor error response handling in proxy plugin#1258
aswmac wants to merge 2 commits into
chimurai:masterfrom
aswmac:master

Conversation

@aswmac

@aswmac aswmac commented Jun 13, 2026

Copy link
Copy Markdown

Updated error handling

avoid leaking any information of the use of proxy to the client, and preserve more detailed log server-side

Motivation and Context

The details of the backend using proxy for services are not for the client, this sanitizes that information

How has this been tested?

The error could not be trapped in my backend code and the client persistently saw an error message that did not leak much information but did include "proxy" which is not for the client to see.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Checklist:

  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.

Summary by CodeRabbit

  • Bug Fixes
    • Error responses now return a consistent, generic upstream error body to clients, reducing exposure of request/URL details.
  • Observability
    • When proxy errors occur, the system now records more complete server-side error details (including request host and URL) to aid troubleshooting.

Updated error handling to avoid leaking any information of the use of proxy to the client, and preserve more detailed log server-side
@coderabbitai

coderabbitai Bot commented Jun 13, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 2223e10a-7785-4204-b32a-1898b08834b0

📥 Commits

Reviewing files that changed from the base of the PR and between 6999eff and aed8d8c.

📒 Files selected for processing (1)
  • src/plugins/default/error-response-plugin.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/plugins/default/error-response-plugin.ts

📝 Walkthrough

Walkthrough

This PR updates the error response plugin to enhance server-side error observability while simplifying client-facing error messages. The plugin now logs complete proxy error details (including request host and URL) to the server console when a response is available, and returns a generic constant body "UPSTREAM_ERROR" to the client instead of the previous sanitized host/URL-based message.

Changes

Error Response Plugin Update

Layer / File(s) Summary
Error logging and generic response body
src/plugins/default/error-response-plugin.ts
Proxy error handling adds server-side console.error logging of full request context and error details, and switches client response body to a generic constant "UPSTREAM_ERROR" instead of a sanitized message built from host/URL.

🎯 2 (Simple) | ⏱️ ~8 minutes

🐰 A logger hops with glee,
Full errors for you and for me!
Generic to send down the wire,
While servers see all that's mire.
Simpler flows, the rabbit's desire! 🌿

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Refactor error response handling in proxy plugin' accurately describes the main change in the PR, which modifies how error responses are handled in the error-response-plugin component.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Caution

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

⚠️ Outside diff range comments (1)
src/plugins/default/error-response-plugin.ts (1)

6-6: ⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Remove unused import.

The sanitize import is no longer used after switching to the generic constant error message.

🧹 Proposed fix
-import { sanitize } from '../../utils/sanitize.js';
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/plugins/default/error-response-plugin.ts` at line 6, Remove the unused
import "sanitize" from the top-level imports in error-response-plugin.ts: locate
the import statement that imports sanitize (import { sanitize } from
'../../utils/sanitize.js';) and delete it so there are no unused imports
remaining after switching to the generic constant error message.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/plugins/default/error-response-plugin.ts`:
- Around line 23-24: The log call in error-response-plugin.ts uses
req.headers.host and req.url directly which can be undefined; update the
console.error invocation to use safe fallbacks (e.g., (req.headers?.host ??
'<no-host>') and (req.url ?? '<no-url>')) so the message never contains
"undefined" and still includes useful context; preserve the err argument so full
error details are logged.

---

Outside diff comments:
In `@src/plugins/default/error-response-plugin.ts`:
- Line 6: Remove the unused import "sanitize" from the top-level imports in
error-response-plugin.ts: locate the import statement that imports sanitize
(import { sanitize } from '../../utils/sanitize.js';) and delete it so there are
no unused imports remaining after switching to the generic constant error
message.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 1e564c64-ac21-48e6-a207-ef577e31906c

📥 Commits

Reviewing files that changed from the base of the PR and between 013dd9b and 6999eff.

📒 Files selected for processing (1)
  • src/plugins/default/error-response-plugin.ts

Comment thread src/plugins/default/error-response-plugin.ts Outdated
fallback values for undefined
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.

1 participant