From 6e17cd8735020bc80f5ea2b4bb5b485cb68416b2 Mon Sep 17 00:00:00 2001 From: Ingmar Vierhaus Date: Thu, 9 Nov 2017 12:05:36 +0100 Subject: [PATCH] Do not suppress errors from requiering handler Errors thrown by `require(pathname)` were previously caught and suppressed here with a wrong messsage to debuglog. Since this is also the code that includes security middlewares, errors should be thrown. --- lib/buildroutes.js | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/lib/buildroutes.js b/lib/buildroutes.js index 87b3ea9..c06340a 100644 --- a/lib/buildroutes.js +++ b/lib/buildroutes.js @@ -160,28 +160,26 @@ function buildSecurity(options, securityDefinitions, routeSecurity) { */ function resolve(basedir, pathname, method) { var handler; + //If the pathname is already a resolved function, return it. + //In the case of x-handler and x-authorize, users can define + //external handler/authorize modules and functions OR override + //existing x-authorize functions. + if (thing.isFunction(pathname)) { + return pathname; + } try { - //If the pathname is already a resolved function, return it. - //In the case of x-handler and x-authorize, users can define - //external handler/authorize modules and functions OR override - //existing x-authorize functions. - if (thing.isFunction(pathname)) { - return pathname; - } - pathname = path.resolve(basedir, pathname); - handler = require(pathname); - - if (thing.isFunction(handler)) { - return handler; - } - - return method && handler[method]; - } - catch (error) { + } catch (error) { utils.debuglog('Could not find %s.', pathname); return; } + handler = require(pathname); + + if (thing.isFunction(handler)) { + return handler; + } + + return method && handler[method]; } module.exports = buildroutes;