'getting response data on logger interceptor
I am trying to log the response data by using logger interceptor, but when I send a new request I get output
before
undefined
after
instead of what i expect to get
before
<response data>
after
this is my log interceptor
export interface Response<T> {
data: T;
}
@injectable({scope: Scope.REQUEST})
export class TransformInterceptor<T> implements NestInterceptor<T,Response<T>>{
intercept(context: ExecutionContext, next: CallHandler): Observable<Response<T>>{
console.log('before')
return next.handle().pipe(tap((data)=>{
console.log(data);
console.log('after');
return data;
}));
}
}
and this is the appModule
@Module({
controllers: [AppController],
providers: [ ControlLogger, AppService, {provide: APPINTERCEPTOR, scope: Scope.REQUEST, useClass: TransformInterceptor}]
})
export class AppModule{}
and i am not sure this is relevent but this is my app controller
@Get('isActive')
requestfunc(@Req() req: Request, @Res res: Response){
res.status(HttpStatus.OK).send('Active')
}
(i have also tried switching the tap to async map)
hope you can help me to log the response data
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|