Closed vanenshi closed 2 years ago
same
did you fix it ?
@mouheb1 when does it happen?
@mouheb1 when does it happen?
I found the source of the problem. in the all-exceptions.filter.ts
the translate
function causes the error.
I manage to temporarily fix the problem by adding a try ... cache
to the message translator. here is my code
// filters/all-exceptions.filter.ts
import type { ArgumentsHost, ExceptionFilter } from "@nestjs/common";
import { Catch, HttpException } from "@nestjs/common";
import type { Response } from "express";
import { I18nService } from "nestjs-i18n";
@Catch(HttpException)
export class AllExceptionsFilter implements ExceptionFilter {
constructor(private readonly i18n: I18nService) {}
async catch(exception: HttpException, host: ArgumentsHost) {
const ctx = host.switchToHttp();
const response = ctx.getResponse<Response>();
const statusCode = exception.getStatus();
let message = exception.getResponse() as {
key: string;
args: Record<string, unknown>;
};
// add try cache because of a error in translate function
try {
message = await this.i18n.translate(message.key, {
lang: ctx.getRequest().i18nLang,
args: message.args,
});
} catch (e) {}
response.status(statusCode).json({ statusCode, message });
}
}
@NarHakobyan it happened when i tried to use an API without being authenticated so i fixed this issue by removing the nexjs-i18n
@vanenshi but you are catching the error and not fixing it so it's like turning around the issue
@NarHakobyan it happened when i tried to use an API without being authenticated so i fixed this issue by removing the nexjs-i18n
@vanenshi but you are catching the error and not fixing it so it's like turning around the issue
as I told you in the previous comment, I just temporarily fix the problem to be able to use the API
I clone the project right now and this error pops up every time there is an exception (HTTP handled exception).
and here is the log of the exception that is causing this error:
and