Skip to content

Http exceptions are loosing default description if cause is provided #15961

@karlismelderis-mckinsey

Description

Is there an existing issue for this?

  • I have searched the existing issues

Current behavior

        const errorCause = new Error('https://www.rfc-editor.org/rfc/rfc2324');
        const error = new ImATeapotException('Easter Egg', {
          cause: errorCause,
        });

looses description: 'I'm a teapot'

while this sets description to default I'm a teapot:

        const error = new ImATeapotException('Easter Egg');

Can you please add this to http exceptions:

const defaultDescription = `I'm a teapot`;
// ...
  constructor(
    objectOrError?: any,
    descriptionOrOptions: string | HttpExceptionOptions = defaultDescription,
  ) {
    const { description = defaultDescription, httpExceptionOptions } =
      HttpException.extractDescriptionAndOptionsFrom(descriptionOrOptions);

https://github.com/nestjs/nest/blob/master/packages/common/exceptions/im-a-teapot.exception.ts#L43

it would allow to pass cause without loosing default error description

Minimum reproduction code

na, hope code snipper in description is enough

Steps to reproduce

No response

Expected behavior

default description or error to be used in not provided in options

NestJS version

10* & 11.*

Packages versions

Node.js version

No response

In which operating systems have you tested?

  • macOS
  • Windows
  • Linux

Other

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    needs triageThis issue has not been looked into

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions