How to Use It

  1. After you import the package , add decorator to your exception:

@LocalizationAwareException('exception.pong')
export class PongException extends ImATeapotException {}
  1. And in your app.module.ts file add this :

import { Module } from '@nestjs/common';
import { provideLocalizationAwareOptions } from '@tradinos/cms-backend-error-handling';

@Module({
   providers: [  
      provideLocalizationAwareOptions({  // if you do not add this will fallback the default 
      getTranslation(host, key, exception) {
        // Your Code Goes Here
      },
    }),
    {
      provide: APP_FILTER,
      useClass: LocalizationAwareExcptionFilter,
    },
  ]
})
export class AppModule {}

How it work ?

  1. Each error in the system will pass through "LocalizationAwareExcptionFilter" .

  2. If the exception were decorated the ExceptionFilter wiil translate the error, otherwise it will fallback to the base exception filter.

  3. To attach the key with error we add @LocalizationAwareException('exception.pong') .

Last updated