Skip to content

Conversation

@lamngockhuong
Copy link
Contributor

@lamngockhuong lamngockhuong commented Nov 10, 2024

Description

The root cause stems from this pull request:
#653

We cannot access the i18nOptions passed from the constructor within the static function I18nContext.current. And when an error occurs in any middleware, the I18nContext will not be initialized, causing this.storage.getStore() to return undefined.

Steps to reproduce this issue:

I use i18n in a GlobalExceptionFilter class:

@Catch()
export class GlobalExceptionFilter implements ExceptionFilter {
private i18n: I18nContext<I18nTranslations>;
catch(exception: any, host: ArgumentsHost): void {
    const { httpAdapter } = this.httpAdapterHost;
    const ctx = host.switchToHttp();
    this.i18n = I18nContext.current<I18nTranslations>(host);
    ...
}

Trigger an error in a different middleware:

image

The error occurs here: I18nContext.current(host);

image

Linked Issues

Additional context

@coveralls
Copy link

Coverage Status

coverage: 90.829% (-0.008%) from 90.837%
when pulling d852410 on lamngockhuong:fix.cannot-access-i18n-options-from-i18n-obj
into ac6e4f9 on toonvanstrijp:main.

@lamngockhuong
Copy link
Contributor Author

@rubiin Please review this PR when you have spare time
Thanks

@rubiin rubiin merged commit 7317aa3 into toonvanstrijp:main Nov 12, 2024
3 checks passed
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

Successfully merging this pull request may close these issues.

3 participants