import { Injectable, NestInterceptor, CallHandler, ExecutionContext } from '@nestjs/common'; import { map } from 'rxjs/operators'; import { Observable } from 'rxjs'; interface Response { data: T; } @Injectable() export class HttpResponseTransformInterceptor implements NestInterceptor> { intercept(context: ExecutionContext, next: CallHandler): Observable> { return next.handle().pipe( map((data) => { const ctx = context.switchToHttp(); const response = ctx.getResponse(); const request = ctx.getRequest(); // const url = request.originalUrl; const statusCode = response.statusCode; const res = { statusCode, message: null, success: true, data, }; // console.info(url, res); return res; }) ); } }