Skip to content

Conversation

@malkovitc
Copy link

Summary

Problem

When creating any built-in HTTP exception with only options:

const error = new BadRequestException('message', { cause: new Error() });

The error field in the response was undefined instead of 'Bad Request'.

Solution

Use destructuring default values to preserve the default description:

const { description = 'Bad Request', httpExceptionOptions } =
  HttpException.extractDescriptionAndOptionsFrom(descriptionOrOptions);

Test Plan

  • Added unit test that verifies all 21 HTTP exceptions preserve their default description when using options with only cause
  • All 1814 tests pass

Related

evgeniy.chernomortsev added 2 commits December 3, 2025 01:40
When resolving multiple default-scoped providers registered under the same
token using `moduleRef.resolve(token, undefined, { each: true })`, the method
was returning the same instance repeated N times instead of all distinct
provider instances.

The issue was in `resolvePerContext` where for static dependency trees it
called `this.get()` which always returned the last registered provider,
ignoring the specific `instanceLink` being processed. Now it returns
`wrapperRef.instance` directly from each instance link.

Closes nestjs#15979
…n using options

When providing HttpExceptionOptions (e.g., { cause }) without an explicit
description, the default description was lost because extractDescriptionAndOptionsFrom()
returns undefined for the description property.

This fix applies the same pattern used in PR nestjs#15962 for ImATeapotException to all
built-in HTTP exceptions: using destructuring default values to preserve the
default description when options are provided without an explicit description.

Closes nestjs#15961
@coveralls
Copy link

Pull Request Test Coverage Report for Build 9a0a27df-0a3e-4dc5-8b82-d0a22de34d2e

Details

  • 1 of 1 (100.0%) changed or added relevant line in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.02%) to 88.963%

Totals Coverage Status
Change from base Build 4ca5c28e-7e66-4111-b582-45a7567e0e4e: 0.02%
Covered Lines: 7327
Relevant Lines: 8236

💛 - Coveralls

@kamilmysliwiec
Copy link
Member

npm run lint:packages fails now

@malkovitc
Copy link
Author

Closing in favor of a new PR that removes unrelated changes (abstract-instance-resolver.ts from a different fix).

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.

Http exceptions are loosing default description if cause is provided

3 participants