import { Injectable , NestInterceptor , ExecutionContext , CallHandler , HttpException } from '@nestjs/common' ; import { Observable } from 'rxjs' ; import { map } from 'rxjs/operators' ; @ Injectable ( ) export class ExceptionInterceptor implements NestInterceptor { intercept ( context , next ) { return next . handle ( ) . pipe ( map ( ( data ) => { if ( data ?. success !== undefined && ! data ?. success && data ?. statusCode ) { throw new HttpException ( data ?. message ?? 'Something went wrong' , data ?. statusCode ) ; } return data ; } ) ) ; } }