@@ -86,6 +86,10 @@ api2.use('/test/testing',function(req,res,next) {
86
86
next ( )
87
87
} )
88
88
89
+ api2 . use ( '/test/error' , function ( req , res , next ) {
90
+ res . error ( 401 , 'Not Authorized' )
91
+ } )
92
+
89
93
90
94
api3 . use ( [ '/test' , '/test/:param1' , '/test2/*' ] , function ( req , res , next ) {
91
95
req . testMiddlewareAll = true
@@ -166,6 +170,10 @@ api2.get('/test/:param1', function(req,res) {
166
170
res . status ( 200 ) . json ( { method : 'get' , middleware : req . testMiddleware ? true : false , middlewareWildcard : req . testMiddlewareWildcard ? true : false , middlewareParam : req . testMiddlewareParam ? true : false , middlewarePath : req . testMiddlewarePath ? true : false } )
167
171
} )
168
172
173
+ api2 . get ( '/test/error' , function ( req , res ) {
174
+ res . status ( 200 ) . json ( { message : 'should not get here' } )
175
+ } )
176
+
169
177
170
178
api3 . get ( '/test' , function ( req , res ) {
171
179
res . status ( 200 ) . json ( { method : 'get' , middleware : req . testMiddlewareAll ? true : false } )
@@ -350,4 +358,13 @@ describe('Middleware Tests:', function() {
350
358
} ) // end it
351
359
352
360
361
+ it ( 'Trigger error in middleware' , async function ( ) {
362
+ let _event = Object . assign ( { } , event , { path : '/test/error' } )
363
+ let result = await new Promise ( r => api2 . run ( _event , { } , ( e , res ) => { r ( res ) } ) )
364
+ expect ( result ) . to . deep . equal ( {
365
+ headers : { 'content-type' : 'application/json' } ,
366
+ statusCode : 401 , body : '{"error":"Not Authorized"}' , isBase64Encoded : false } )
367
+ } ) // end it
368
+
369
+
353
370
} ) // end MIDDLEWARE tests
0 commit comments