import { Logger } from 'log4js' ; import { ApiResponseUtilInterface } from '../../interface/api-response-util-interface' ; export class RabbitManagerResponseUtil implements ApiResponseUtilInterface { private readonly logger : Logger ; private readonly verbose : boolean = ! ! process . env . VERBOSE ; constructor ( logger ) { this . logger = logger ; } analDelete ( url , params , headers , code , data , rsHeader ) { if ( this . verbose ) { this . printVerbose ( url , params , headers , code , data , rsHeader ) ; } switch ( code ) { case 200 : return true ; case 204 : return true ; default : this . logger . warn ( `un-caught response code: ${ code } from ${ url }` ) ; return { code : code , header : rsHeader , data : data , } ; } } public analGet ( url , params , headers , code , data , rsHeader ) { if ( this . verbose ) { this . printVerbose ( url , params , headers , code , data , rsHeader ) ; } switch ( code ) { case 200 : return data ; case 404 : this . logger . warn ( `Cant Found Target Resource ${ url }` ) ; return false ; default : this . logger . warn ( `Un-Caught response code: ${ code } from ${ url }` ) ; return { code : code , header : rsHeader , data : data , } ; } } analPost ( url , params , headers , code , data , rsHeader ) { if ( this . verbose ) { this . printVerbose ( url , params , headers , code , data , rsHeader ) ; } return Promise . resolve ( undefined ) ; } analPut ( url , params , headers , code , data , rsHeader ) { if ( this . verbose ) { this . printVerbose ( url , params , headers , code , data , rsHeader ) ; } switch ( code ) { case 201 : return true ; case 204 : return false ; default : this . logger . warn ( `un-caught response code: ${ code } from ${ url }` ) ; return { code : code , header : rsHeader , data : data , } ; } } private printVerbose ( url , params , headers , code , data , rsHeader ) { this . logger . info ( `Requested Url: ${ url }
        headers: ${ JSON . stringify ( headers ) || '' }
        Params: ${ params || '' }
        Response Code: ${ code }
        Header: ${ rsHeader ? JSON . stringify ( rsHeader ) : '' }
        data: ${ data ? JSON . stringify ( data ) : '' }` ) ; } }