Skip to content

Commit 659d947

Browse files
committed
fix: eniroment declaration and error handling of execute method
1 parent 9d18898 commit 659d947

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

src/server.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,13 @@ class CoCreateLazyLoader {
156156
const name = methodPath.shift()
157157

158158
const apis = await this.getApiKey(data, name)
159-
const environment = data.environment || 'production';
159+
let environment = 'production';
160+
161+
if (data.environment)
162+
environment = data.environment
163+
else if (data.host.startsWith('dev.') || data.host.startsWith('test.'))
164+
environment = 'test'
165+
160166
const key = apis[environment].key;
161167
if (!key)
162168
throw new Error(`Missing ${name} key in organization apis object`);
@@ -199,8 +205,9 @@ class CoCreateLazyLoader {
199205
async webhooks(config, data, name) {
200206
try {
201207
const apis = await this.getApiKey(data, name)
202-
let environment = data.environment || 'production';
203-
if (data.host.startsWith('dev.') || data.host.startsWith('test.'))
208+
if (data.environment)
209+
environment = data.environment
210+
else if (data.host.startsWith('dev.') || data.host.startsWith('test.'))
204211
environment = 'test'
205212

206213
const key = apis[environment].key;
@@ -443,7 +450,7 @@ async function executeMethod(method, methodPath, instance, params) {
443450
return await Method[methodName](...params)
444451
}
445452
} catch (error) {
446-
throw new Error(`Method ${method} not found.`);
453+
throw new Error(error);
447454
}
448455
}
449456

0 commit comments

Comments
 (0)