import { ExecutionContext , HttpException , Injectable } from '@nestjs/common' ; import { HTTP_CODE_METADATA } from '@nestjs/common/constants' ; import { AbstractInterceptorService } from './abstract-interceptor.service' ; @ Injectable ( ) export abstract class HttpInterceptorService extends AbstractInterceptorService { getStatus ( context , inColor , error ? ) { let status ; const res = this . getResponse ( context ) ; status = res . statusCode ; const reflectStatus = this . reflector . get < number > ( HTTP_CODE_METADATA , context . getHandler ( ) ) ; status = reflectStatus || status ; if ( error ) { status = this . determineStatusCodeFromError ( error ) ; } return inColor ? this . wrapInColor ( status ) : status . toString ( ) ; } private determineStatusCodeFromError ( error ) { let status ; try { status = ( error as HttpException ) . getStatus ( ) ; } catch ( err ) { status = 500 ; } return status ; } param context returns getResponse ( context ) { return context . switchToHttp ( ) . getResponse ( ) ; } param context returns getRequest ( context ) { return context . switchToHttp ( ) . getRequest ( ) ; } }