import * as e from 'express' ; import { isFunction } from 'util' ; import { InternalServerProblem , Problem } from '../../../domain/entities/Problem' ; e . response . sendProblem = function ( problem ) : void { this . status ( problem . status ) ; this . json ( problem ) ; } ; e . response . sendPromise = function < T > ( p ) : void { let promise ; if ( isFunction ( p ) ) { promise = ( < ( ) => Promise < T > > p ) ( ) ; } else { promise = < Promise < T > > p ; } promise . then ( ( res ) => { if ( res instanceof Problem ) { this . status ( res . status ) ; } this . json ( res ) ; } ) . catch ( ( err ) => { console . log ( err ) ; this . sendProblem ( new InternalServerProblem ( { detail : JSON . stringify ( err ) } ) ) ; } ) ; } ; export = e ;