@@ -60,13 +60,16 @@ module.exports = (options = {}) => {
6060 // global middlewares holder
6161 const middlewares = [ ]
6262 // routes registration shortcut factory
63- const addRoute = ( method ) => ( path , ...args ) => {
64- routeRegister ( app , method , path , args )
63+ const addRoute = ( methods ) => ( path , ...args ) => {
64+ routeRegister ( app , methods , path , args )
6565
6666 // supporting method chaining for routes registration
6767 return app
6868 }
6969
70+ // error handler
71+ const errorHandler = options . errorHandler || ( ( err , req , res ) => res . send ( err ) )
72+
7073 // the "restana" service interface
7174 const app = {
7275 /**
@@ -133,13 +136,13 @@ module.exports = (options = {}) => {
133136 ...middlewares . slice ( 0 ) ,
134137 {
135138 context : { } ,
136- handler : handlerCall ( handler , ctx ) // -> Function
139+ handler : handlerCall ( handler , ctx , errorHandler ) // -> Function
137140 }
138- ] , req , res ) ( )
141+ ] , req , res , errorHandler ) ( )
139142 } else {
140143 // directly call the route handler only
141144 // NOTE: we do this to increase performance
142- handlerCall ( handler , ctx ) ( req , res )
145+ handlerCall ( handler , ctx , errorHandler ) ( req , res )
143146 }
144147 } )
145148 } else {
@@ -170,7 +173,7 @@ module.exports = (options = {}) => {
170173 router . lookup ( req , res )
171174 }
172175 }
173- ] , req , res ) ( )
176+ ] , req , res , errorHandler ) ( )
174177 } else {
175178 // directly call the request router
176179 // NOTE: we do this to increase performance
0 commit comments