Skip to content

refactor(errors): use HttpProxyMiddlewareError class#1264

Merged
chimurai merged 1 commit into
masterfrom
refactor-errors
Jun 17, 2026
Merged

refactor(errors): use HttpProxyMiddlewareError class#1264
chimurai merged 1 commit into
masterfrom
refactor-errors

Conversation

@chimurai

@chimurai chimurai commented Jun 17, 2026

Copy link
Copy Markdown
Owner

Summary by CodeRabbit

  • Bug Fixes
    • Improved error reporting with consistent error codes for configuration failures (missing target, invalid path filters, invalid path rewrites)
    • Enhanced error messages for multipart form data validation

@coderabbitai

coderabbitai Bot commented Jun 17, 2026

Copy link
Copy Markdown

Review Change Stack

Caution

Review failed

Pull request was closed or merged during review

📝 Walkthrough

Walkthrough

The ERRORS enum is removed from src/errors.ts. All four modules that previously threw generic errors using ERRORS constants (configuration.ts, path-filter.ts, path-rewriter.ts, stringify-form-data.ts) are updated to throw HttpProxyMiddlewareError with explicit messages and module-specific error code strings. Unit tests are updated to assert typed errors and specific codes.

Changes

Typed Error Migration

Layer / File(s) Summary
Remove ERRORS enum and throw typed errors in source modules
src/errors.ts, src/configuration.ts, src/path-filter.ts, src/path-rewriter.ts, src/handlers/fix-request-body-utils/stringify-form-data.ts
Deletes the ERRORS enum entirely. Each module replaces its ERRORS-based generic Error throw with HttpProxyMiddlewareError carrying a specific code: ERR_CONFIG_FACTORY_TARGET_MISSING, HPM_INVALID_PATH_FILTER_CONFIG, HPM_INVALID_PATH_FILTER_ARRAY_CONFIG, HPM_INVALID_PATH_REWRITER_CONFIG, and HPM_ERR_INVALID_MULTIPART_{BOUNDARY,FIELD_NAME,FIELD_VALUE}. HPM_ERR_INVALID_MULTIPART is now exported from stringify-form-data.ts.
Update unit tests to assert typed error codes
test/unit/configuration.spec.ts, test/unit/path-filter.spec.ts, test/unit/path-rewriter.spec.ts
Imports HttpProxyMiddlewareError in each test file and updates error-throw assertions to verify both the error class and the specific code property value for each invalid-configuration scenario.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • chimurai/http-proxy-middleware#1197: Refactors isValidRewriteConfig typings and signatures in src/path-rewriter.ts, the same function where this PR changes the thrown error type to HttpProxyMiddlewareError with HPM_INVALID_PATH_REWRITER_CONFIG.

Poem

🐰 Hop, hop, no more generic throws!
Each error now a typed bunny that glows,
HttpProxyMiddlewareError in every lair,
With codes like HPM_INVALID to declare.
The ERRORS enum hops away for good —
Typed errors blooming just as they should! 🌸

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main refactoring objective: replacing generic error handling with the HttpProxyMiddlewareError class across multiple modules.
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 docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch refactor-errors

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.

@pkg-pr-new

pkg-pr-new Bot commented Jun 17, 2026

Copy link
Copy Markdown
npm i https://pkg.pr.new/http-proxy-middleware@1264

commit: 97bcb6f

@coveralls

Copy link
Copy Markdown

Coverage Status

coverage: 95.183% (-0.06%) from 95.238% — refactor-errors into master

@chimurai chimurai merged commit 3695b93 into master Jun 17, 2026
25 of 26 checks passed
@chimurai chimurai deleted the refactor-errors branch June 17, 2026 19:44
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