nestjs-i18n
Advanced tools
Comparing version 10.3.6 to 10.3.7
@@ -11,3 +11,4 @@ import { ArgumentsHost, ExceptionFilter, ValidationError } from '@nestjs/common'; | ||
protected flattenValidationErrors(validationErrors: ValidationError[]): string[]; | ||
protected buildResponseBody(host: ArgumentsHost, exc: I18nValidationException, errors: string[] | I18nValidationError[] | object): Record<string, unknown>; | ||
} | ||
export {}; |
@@ -29,15 +29,13 @@ "use strict"; | ||
}); | ||
const normalizedErrors = this.normalizeValidationErrors(errors); | ||
switch (host.getType()) { | ||
case 'http': | ||
const response = host.switchToHttp().getResponse(); | ||
const responseBody = this.buildResponseBody(host, exception, normalizedErrors); | ||
response | ||
.status(this.options.errorHttpStatusCode || exception.getStatus()) | ||
.send({ | ||
statusCode: this.options.errorHttpStatusCode || exception.getStatus(), | ||
message: exception.getResponse(), | ||
errors: this.normalizeValidationErrors(errors), | ||
}); | ||
.send(responseBody); | ||
break; | ||
case 'graphql': | ||
exception.errors = this.normalizeValidationErrors(errors); | ||
exception.errors = normalizedErrors; | ||
return exception; | ||
@@ -67,2 +65,16 @@ } | ||
} | ||
buildResponseBody(host, exc, errors) { | ||
if ('responseBodyFormatter' in this.options) { | ||
return this.options.responseBodyFormatter(host, exc, errors); | ||
} | ||
else { | ||
return { | ||
statusCode: this.options.errorHttpStatusCode === undefined | ||
? exc.getStatus() | ||
: this.options.errorHttpStatusCode, | ||
message: exc.getResponse(), | ||
errors, | ||
}; | ||
} | ||
} | ||
}; | ||
@@ -69,0 +81,0 @@ I18nValidationExceptionFilter = __decorate([ |
@@ -1,2 +0,3 @@ | ||
import { HttpStatus, ValidationError } from '@nestjs/common'; | ||
import { ArgumentsHost, HttpStatus, ValidationError } from '@nestjs/common'; | ||
import { I18nValidationException } from './i18n-validation-error.interface'; | ||
interface I18nValidationExceptionFilterCommonErrorsOption { | ||
@@ -10,3 +11,4 @@ errorHttpStatusCode?: HttpStatus | number; | ||
errorFormatter?: (errors: ValidationError[]) => object; | ||
responseBodyFormatter?: (host: ArgumentsHost, exc: I18nValidationException, formattedErrors: object) => Record<string, unknown>; | ||
} | ||
export {}; |
@@ -21,3 +21,3 @@ "use strict"; | ||
exports.convertObjectToTypeDefinition = convertObjectToTypeDefinition; | ||
const printer = ts.createPrinter(); | ||
const printer = ts.createPrinter({ newLine: ts.NewLineKind.LineFeed, }); | ||
const createTypesFile = async (object) => { | ||
@@ -24,0 +24,0 @@ const sourceFile = ts.createSourceFile('placeholder.ts', '', ts.ScriptTarget.ESNext, true, ts.ScriptKind.TS); |
{ | ||
"name": "nestjs-i18n", | ||
"version": "10.3.6", | ||
"version": "10.3.7", | ||
"homepage": "https://nestjs-i18n.com", | ||
@@ -35,6 +35,6 @@ "description": "The i18n module for Nest.", | ||
"build:lib": "npx rimraf dist && tsc -p tsconfig.build.json", | ||
"prepublish:npm": "npm run build", | ||
"publish:npm": "npm publish --access public", | ||
"prepublish:next": "npm run build", | ||
"publish:next": "npm publish --access public --tag next", | ||
"prerelease": "npm run build && bumpp", | ||
"release": "npm publish --access public", | ||
"prerelease:next": "npm run build", | ||
"release:next": "npm publish --access public --tag next", | ||
"format": "prettier --write \"src/**/*.ts\" \"tests/**/*.ts\"", | ||
@@ -90,2 +90,3 @@ "test": "jest --config ./tests/jest-test.json", | ||
"apollo-server-express": "^3.9.0", | ||
"bumpp": "^9.2.0", | ||
"class-transformer": "^0.5.1", | ||
@@ -92,0 +93,0 @@ "class-validator": "^0.14.0", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
338017
2438
50