toonvanstrijp / nestjs-i18n

The i18n module for nestjs.
https://nestjs-i18n.com
Other
656 stars 113 forks source link

Server error occurs when 'validationError.target' value in 'ValidationPipe' options is set to 'false'. #659

Closed pejold closed 2 months ago

pejold commented 2 months ago

Describe the bug

I am using nestjs-i18n for DTO validation with the global validation method. I attempted to exclude the 'target' property from the detailed error response by configuring the validationError.target option in the ValidationPipe, as shown below:

// src/main.ts
import { NestFactory } from '@nestjs/core';
import { NestExpressApplication } from '@nestjs/platform-express';
import { I18nValidationExceptionFilter, I18nValidationPipe } from 'nestjs-i18n';

async function bootstrap() {
  const app = await NestFactory.create<NestExpressApplication>(AppModule);

  app.useGlobalPipes(
    new I18nValidationPipe({
      validationError: {
        target: false,
      },
    }),
  );

  app.useGlobalFilters(
    new I18nValidationExceptionFilter({
      detailedErrors: true,
    }),
  );
}

However, with this configuration, any request that fails validation results in a server error response like this:

{
    "statusCode": 500,
    "message": "Internal server error"
}

The issue is caused by the commit fdd63a4, which includes code that attempts to access the target property from the error object.

Reproduction

Set 'validationError.target' value in 'ValidationPipe' to 'false'.

System Info

System:
    OS: macOS 14.6.1
    CPU: (8) arm64 Apple M2
    Memory: 161.83 MB / 16.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 20.17.0 - /opt/homebrew/opt/node@20/bin/node
    Yarn: 1.22.22 - /opt/homebrew/bin/yarn
    npm: 10.8.2 - /opt/homebrew/opt/node@20/bin/npm
  Browsers:
    Chrome: 128.0.6613.120
    Edge: 128.0.2739.67
    Safari: 17.6

Used Package Manager

yarn

Validations