toonvanstrijp / nestjs-i18n

The i18n module for nestjs.
https://nestjs-i18n.com
Other
625 stars 102 forks source link

fix: I18nContext.current() undefined when using additional interceptors #594

Closed lucas-gregoire closed 8 months ago

lucas-gregoire commented 8 months ago

Description

I discovered a bug when using disableMiddleware: true. When relying on I18nLanguageInterceptor to initialize the I18nContext, it's not possible to use another interceptor on the same endpoint. When doing so, the AsyncLocalStorage containing the i18n context is broken: I18nContext.current() always returns undefined.

How to reproduce

Additional context

I did something similar to the nestjs-cls's interceptor implementation: https://github.com/Papooch/nestjs-cls/blob/main/packages/core/src/lib/cls-initializers/cls.interceptor.ts I just simplified it by passing the observer directly to the subscribe method. I added a test in i18n-disable-middleware.e2e.spec.ts to avoid regressions.

See also:

coveralls commented 8 months ago

Coverage Status

coverage: 90.869% (+0.1%) from 90.764% when pulling 45d148d584357591d3103b867e501f82d05b378c on lucas-gregoire:fix/undefined-current-context into 0774e23b6e64fbfa7b5044e87c86e2b0f55fe7b7 on toonvanstrijp:main.