From 53f68c5383d8c5cca9caec1f9e9a6abff194212e Mon Sep 17 00:00:00 2001 From: josieusa Date: Wed, 4 Jan 2017 10:36:30 +0100 Subject: [PATCH] Fix corner case of missing context --- server/current-context.js | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/server/current-context.js b/server/current-context.js index a4054b1..f5649ee 100644 --- a/server/current-context.js +++ b/server/current-context.js @@ -78,19 +78,22 @@ LoopBackContext.createContext = function(scopeName) { process.context[scopeName] = ns; // Set up LoopBackContext.getCurrentContext() LoopBackContext.getCurrentContext = function() { - var boundMethods = { - get: ns.bind(ns.get).bind(ns), - set: ns.bind(ns.set).bind(ns), - }; - var handler = { - get: function(target, name) { - return ['get', 'set'].includes(name) ? - boundMethods[name] : - target[name]; - }, - }; - var proxy = new Proxy(ns, handler); - return ns && ns.active ? proxy : null; + if (ns && ns.active) { + var boundMethods = { + get: ns.bind(ns.get).bind(ns), + set: ns.bind(ns.set).bind(ns), + }; + var handler = { + get: function(target, name) { + return ['get', 'set'].includes(name) ? + boundMethods[name] : + target[name]; + }, + }; + return new Proxy(ns, handler); + } else { + return null; + } }; } return ns;