Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ERROR [RpcExceptionsHandler] I18n context undefined #637

Open
5 tasks done
sg-milad opened this issue May 26, 2024 · 1 comment
Open
5 tasks done

ERROR [RpcExceptionsHandler] I18n context undefined #637

sg-milad opened this issue May 26, 2024 · 1 comment

Comments

@sg-milad
Copy link

sg-milad commented May 26, 2024

Describe the bug

I am trying to implement i18n in microservice. its works completely fine in HTTP requests but when I use it in my microservices I get this error
gateway:
[Nest] 579618 - 05/26/2024, 11:01:13 AM ERROR [ExceptionsHandler] Internal server error
microservice app:

[Nest] 578651  - 05/26/2024, 11:00:19 AM   ERROR [RpcExceptionsHandler] I18n context undefined
I18nError: I18n context undefined
    at /home/sg-milad/Downloads/clone/igaming-platform-backend/prediction/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected][email protected][email protected]/node_modules/nestjs-i18n/src/decorators/i18n.decorator.ts:14:11
    at /home/sg-milad/Downloads/clone/igaming-platform-backend/prediction/node_modules/.pnpm/@[email protected]_@[email protected]_@[email protected]_@nestjs+platform-exp_3itvyzrtyhpuen4ihidhhpk5f4/node_modules/@nestjs/core/helpers/context-utils.js:43:28
    at resolveParamValue (/home/sg-milad/Downloads/clone/igaming-platform-backend/prediction/node_modules/.pnpm/@[email protected]_@[email protected]_@[email protected]_amqp-connection-mana_dmbtl4esns5bxhksz4zyh4cgji/node_modules/@nestjs/microservices/context/rpc-context-creator.js:105:31)
    at Array.map (<anonymous>)

//
this my config in app.module gateway

       I18nModule.forRoot({
            fallbackLanguage: "en",
            loaderOptions: {
                path: join(__dirname, "/i18n/"),
                watch: true,
            },
            resolvers: [
                { use: QueryResolver, options: ["lang"] },
                AcceptLanguageResolver,
                new HeaderResolver(["x-lang"]),
            ],
            typesOutputPath: developmentEnv() ? path.join(__dirname, '../src/shared/generated/i18n.generated.ts') : undefined,
        }),
  app.connectMicroservice<MicroserviceOptions>(mainClientMicroservice(configService), { inheritAppConfig: true });
constructor(@Inject("somthing") private readonly client: ClientRMQ,) { }
    async getHello() {
        return await lastValueFrom<string>(this.client.send("hello", {}))
    }

and my microservice app:

@MessagePattern("hello")
    getHello(@I18n() i18n: I18nContext): string {
        return i18n.t("messages.hello")
    }

I use rabbitMq

Reproduction

please tell me if the the information i provided is not enough

System Info

System:
    OS: Linux 6.5 Ubuntu 22.04.4 LTS 22.04.4 LTS (Jammy Jellyfish)
    CPU: (8) x64 AMD Ryzen 7 3700U with Radeon Vega Mobile Gfx
    Memory: 2.97 GB / 9.58 GB
    Container: Yes
    Shell: 5.8.1 - /usr/bin/zsh
  Binaries:
    Node: 18.17.1 - /usr/local/bin/node
    npm: 10.2.5 - /usr/local/bin/npm
    pnpm: 8.7.1 - /usr/local/bin/pnpm
// my package.json
  "amqp-connection-manager": "^4.1.14",
   "nestjs-i18n": "^10.4.0",
  "amqplib": "^0.10.3",
nestjs version 10

Used Package Manager

pnpm

Validations

  • Follow our Code of Conduct
  • Read the Contributing Guide.
  • Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
  • Check that this is a concrete bug. For Q&A, please open a GitHub Discussion instead.
  • The provided reproduction is a minimal reproducible of the bug.
@fromage9747
Copy link

I have the exact same issue. I thought I was executing code before the i18n module had loaded but if I manually hard code a language key into my code it works fine, so now I am passing the fallback language key as an environment variable as fallbackLanguage parameter is not working.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants