我想在class-validatorNestjs graphql 的错误消息中使用本地化。但我无法设置翻译后的消息作为响应并将其返回。我尝试了很多解决方案,例如response.status(400).json({....})发送修改后的响应,但这没有用,
我用过了,
providers: [
{
provide: APP_FILTER,
useClass: AllExceptionFilter,
},
Run Code Online (Sandbox Code Playgroud)
],
我的AllExceptionFilter.ts是
import { Catch, ArgumentsHost, BadRequestException } from '@nestjs/common';
import { GqlExceptionFilter, GqlArgumentsHost } from '@nestjs/graphql';
import { I18nService } from 'nestjs-i18n';
@Catch(BadRequestException)
export class AllExceptionFilter implements GqlExceptionFilter {
constructor(private readonly i18n: I18nService) {}
async catch(exception: BadRequestException, host: ArgumentsHost) {
const gqlHost = GqlArgumentsHost.create(host);
const translatedMessage = await this.i18n.translate('validation.NotEmpty', {
lang: 'en',
});
// In this place I want the modifications …Run Code Online (Sandbox Code Playgroud)