Skip to content

Commit

Permalink
fix: eniroment declaration and error handling of execute method
Browse files Browse the repository at this point in the history
  • Loading branch information
frankpagan committed Apr 27, 2024
1 parent 9d18898 commit 659d947
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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`);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}

Expand Down

0 comments on commit 659d947

Please sign in to comment.