From 659d947af1226c77b4cbcbaaed10596ade73183f Mon Sep 17 00:00:00 2001 From: frankpagan Date: Sat, 27 Apr 2024 00:47:02 +0000 Subject: [PATCH] fix: eniroment declaration and error handling of execute method --- src/server.js | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/server.js b/src/server.js index 4b7a264..f310b91 100644 --- a/src/server.js +++ b/src/server.js @@ -156,7 +156,13 @@ class CoCreateLazyLoader { const name = methodPath.shift() const apis = await this.getApiKey(data, name) - const environment = data.environment || 'production'; + let environment = 'production'; + + if (data.environment) + environment = data.environment + else if (data.host.startsWith('dev.') || data.host.startsWith('test.')) + environment = 'test' + const key = apis[environment].key; if (!key) throw new Error(`Missing ${name} key in organization apis object`); @@ -199,8 +205,9 @@ class CoCreateLazyLoader { async webhooks(config, data, name) { try { const apis = await this.getApiKey(data, name) - let environment = data.environment || 'production'; - if (data.host.startsWith('dev.') || data.host.startsWith('test.')) + if (data.environment) + environment = data.environment + else if (data.host.startsWith('dev.') || data.host.startsWith('test.')) environment = 'test' const key = apis[environment].key; @@ -443,7 +450,7 @@ async function executeMethod(method, methodPath, instance, params) { return await Method[methodName](...params) } } catch (error) { - throw new Error(`Method ${method} not found.`); + throw new Error(error); } }