Skip to content

fix(common): Add missing exception classes to HttpErrorByCode#17256

Closed
Se3do wants to merge 1 commit into
nestjs:masterfrom
Se3do:fix/http-error-by-code-missing-exceptions
Closed

fix(common): Add missing exception classes to HttpErrorByCode#17256
Se3do wants to merge 1 commit into
nestjs:masterfrom
Se3do:fix/http-error-by-code-missing-exceptions

Conversation

@Se3do

@Se3do Se3do commented Jul 4, 2026

Copy link
Copy Markdown
Contributor

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Other... Please describe:

What is the current behavior?

HttpErrorByCode map in packages/common/utils/http-error-by-code.util.ts is missing MisdirectedException (421) and HttpVersionNotSupportedException (505). Both classes exist on disk and are exported from packages/common/exceptions/index.ts, but are absent from the ErrorHttpStatusCode type union and the HttpErrorByCode Record. Using errorHttpStatusCode: HttpStatus.MISDIRECTED in pipe options causes a TypeScript type error, and HttpErrorByCode[HttpStatus.MISDIRECTED] returns undefined at runtime.

Issue Number: N/A

What is the new behavior?

Both MisdirectedException and HttpVersionNotSupportedException are now imported, added to the ErrorHttpStatusCode type union, and mapped in the HttpErrorByCode Record — consistent with the 19 other exception classes already present. Added 5 unit tests verifying all 21 entries resolve to valid HttpException subclasses with correct status codes.

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

HttpErrorByCode map was missing MisdirectedException (421) and HttpVersionNotSupportedException (505) that already existed on disk.

Added imports, type union entries, and map entries. Added test file verifying all entries resolve to valid HttpException subclasses.
Copilot AI review requested due to automatic review settings July 4, 2026 12:55

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes missing HTTP exception mappings in HttpErrorByCode by adding support for 421 MISDIRECTED and 505 HTTP_VERSION_NOT_SUPPORTED, aligning runtime behavior and TypeScript typing with the existing built-in exception set.

Changes:

  • Add MisdirectedException and HttpVersionNotSupportedException to the ErrorHttpStatusCode union and HttpErrorByCode record.
  • Add a new test suite for HttpErrorByCode to validate mappings and default messages.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
packages/common/utils/http-error-by-code.util.ts Extends the status-code-to-exception mapping and the corresponding status code union to include 421 and 505.
packages/common/test/utils/http-error-by-code.util.spec.ts Adds tests for HttpErrorByCode coverage, mapping correctness, and default messages for the newly included exceptions.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +11 to +36
it('should have an entry for every ErrorHttpStatusCode', () => {
const expectedCodes = [
HttpStatus.BAD_GATEWAY,
HttpStatus.BAD_REQUEST,
HttpStatus.CONFLICT,
HttpStatus.FORBIDDEN,
HttpStatus.GATEWAY_TIMEOUT,
HttpStatus.GONE,
HttpStatus.HTTP_VERSION_NOT_SUPPORTED,
HttpStatus.I_AM_A_TEAPOT,
HttpStatus.INTERNAL_SERVER_ERROR,
HttpStatus.METHOD_NOT_ALLOWED,
HttpStatus.MISDIRECTED,
HttpStatus.NOT_ACCEPTABLE,
HttpStatus.NOT_FOUND,
HttpStatus.NOT_IMPLEMENTED,
HttpStatus.PAYLOAD_TOO_LARGE,
HttpStatus.PRECONDITION_FAILED,
HttpStatus.REQUEST_TIMEOUT,
HttpStatus.SERVICE_UNAVAILABLE,
HttpStatus.UNAUTHORIZED,
HttpStatus.UNPROCESSABLE_ENTITY,
HttpStatus.UNSUPPORTED_MEDIA_TYPE,
];
expect(entries.length).to.equal(expectedCodes.length);
});
expect(entries.length).to.equal(expectedCodes.length);
});

it('should map every code to a class that extends HttpException', () => {
@coveralls

coveralls commented Jul 4, 2026

Copy link
Copy Markdown

Coverage Report for CI Build 19898

Coverage remained the same at 89.924%

Details

  • Coverage remained the same as the base build.
  • Patch coverage: No coverable lines changed in this PR.
  • No coverage regressions found.

Uncovered Changes

No uncovered changes found.

Coverage Regressions

No coverage regressions found.


Coverage Stats

Coverage Status
Relevant Lines: 8644
Covered Lines: 7773
Line Coverage: 89.92%
Relevant Branches: 2947
Covered Branches: 2390
Branch Coverage: 81.1%
Branches in Coverage %: No
Coverage Strength: 56.66 hits per line

💛 - Coveralls

@Se3do Se3do closed this Jul 4, 2026
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