@@ -53,7 +53,7 @@ class HandlerProxy<A extends HandlerAuxBase> {
5353 public call = async (
5454 middleware : HandlerMiddleware < A > ,
5555 handler : Handler < A > ,
56- ) : Promise < any [ ] > => {
56+ ) => {
5757 try {
5858 this . aux = await middleware . auxPromise ;
5959 } catch ( error ) {
@@ -85,20 +85,23 @@ class HandlerProxy<A extends HandlerAuxBase> {
8585 handlers . map ( each => this . safeCall ( each , okResponsible , errorHandlers ) ) ,
8686 ) ;
8787
88- const result = [
88+ const results = [
8989 ...( await iterate ( beginHandlers ) ) ,
9090 ...( await iterate ( actualHandler , true ) ) ,
9191 ...( await iterate ( endHandlers ) ) ,
92- ] ;
92+ ] . filter ( x => x ) ;
9393 // In test phase, throws any exception if there was.
9494 if ( process . env . NODE_ENV === 'test' ) {
95- for ( const each of result ) {
95+ for ( const each of results ) {
9696 if ( each instanceof Error ) {
97+ logger . error ( `Error occurred: ${ stringifyError ( each ) } ` ) ;
9798 throw each ;
9899 }
99100 }
100101 }
101- return result ;
102+ results . forEach ( result =>
103+ logger . silly ( `middleware result : ${ JSON . stringify ( result ) } ` ) ,
104+ ) ;
102105 } ;
103106
104107 private safeCall = async (
@@ -159,11 +162,12 @@ const build = <Aux extends HandlerAuxBase>(
159162 plugins : Array < HandlerPluginBase < any > > ,
160163) => {
161164 const middleware = new HandlerMiddleware < Aux > ( plugins ) ;
162- return ( handler : Handler < Aux > ) => async (
165+ return ( handler : Handler < Aux > ) => (
163166 event : any ,
164167 context : any ,
165168 callback : any ,
166- ) =>
169+ ) => {
167170 new HandlerProxy < Aux > ( event , context , callback ) . call ( middleware , handler ) ;
171+ } ;
168172} ;
169173export default build ;
0 commit comments