Skip to content

fix(event-handler): correct InvalidHttpMethodError name#5254

Open
svozza wants to merge 5 commits into
mainfrom
fix/event-handler-invalid-http-method-error-name
Open

fix(event-handler): correct InvalidHttpMethodError name#5254
svozza wants to merge 5 commits into
mainfrom
fix/event-handler-invalid-http-method-error-name

Conversation

@svozza
Copy link
Copy Markdown
Contributor

@svozza svozza commented May 14, 2026

Summary

InvalidHttpMethodError's constructor incorrectly set this.name = 'InvalidEventError' (a copy-paste from the sibling class declared just above it in errors.ts). Two distinct error classes shared the same name, breaking the name-based dispatch fallback in ErrorHandlerRegistry.resolve (the third resolution step used as a safety net for cross-module/bundling scenarios where instanceof may fail) — an InvalidHttpMethodError would route to a handler registered for InvalidEventError.

Changes

  • Fix InvalidHttpMethodError to set this.name = 'InvalidHttpMethodError' in packages/event-handler/src/http/errors.ts.
  • Add direct unit coverage for InvalidEventError and InvalidHttpMethodError in tests/unit/http/errors.test.ts (asserting .name, .message, and instanceof for each).
  • Extend the existing parametrised it.each in tests/unit/http/errors.test.ts to assert error.name === errorType for every HttpError subclass — guards all 9 of them against the same copy-paste class of bug.
  • Add converter-level coverage in tests/unit/http/converters.test.ts for the previously-unexercised unsupported-method branch in proxyEventToWebRequest, parametrised over API Gateway V1, V2, and ALB events. Asserts both instanceof InvalidHttpMethodError and err.name === 'InvalidHttpMethodError' (the .name check is load-bearing — toThrow(Class) alone would still pass with the bug present).

Issue number: closes #5251


By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Disclaimer: We value your time and bandwidth. As such, any pull requests created on non-triaged issues might not be successful.

@powertools-for-aws-oss-automation powertools-for-aws-oss-automation Bot added the size/M PR between 30-99 LOC label May 14, 2026
@svozza svozza requested a review from dreamorosi May 14, 2026 14:11
@powertools-for-aws-oss-automation powertools-for-aws-oss-automation Bot added size/M PR between 30-99 LOC and removed size/M PR between 30-99 LOC labels May 14, 2026
svozza added 4 commits May 15, 2026 09:58
InvalidHttpMethodError's constructor set this.name to 'InvalidEventError'
(copy-paste from the sibling class above it). Name-based dispatch in
ErrorHandlerRegistry.resolve would mis-route the method error to an
InvalidEventError handler.

Fixes #5251.
Removes the ErrorHandlerRegistry test asserting InvalidHttpMethodError
is not routed to an InvalidEventError handler via name-fallback. The
errors.test.ts and converters.test.ts coverage already pins the .name
fix; this registry-level test is redundant.
@svozza svozza force-pushed the fix/event-handler-invalid-http-method-error-name branch from e4e58c9 to adc0e70 Compare May 15, 2026 09:02
@powertools-for-aws-oss-automation powertools-for-aws-oss-automation Bot added size/M PR between 30-99 LOC and removed size/M PR between 30-99 LOC labels May 15, 2026
@powertools-for-aws-oss-automation powertools-for-aws-oss-automation Bot added size/M PR between 30-99 LOC and removed size/M PR between 30-99 LOC labels May 17, 2026
@sonarqubecloud
Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/M PR between 30-99 LOC

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: event-handler HTTP InvalidHttpMethodError carries the wrong name ("InvalidEventError")

1 participant