Skip to content

Commit

Permalink
fix: No more errors when empty New Relic metrics attribute/header arr…
Browse files Browse the repository at this point in the history
…ays in config file

Fixes #467
  • Loading branch information
mountaindude committed May 20, 2022
1 parent 3b34c49 commit 81e65ca
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/routes/newrelic_metric.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@ async function handlerPostNewRelicMetric(request, reply) {
if (globals.config.has('Butler.restServerEndpointsConfig.newRelic.postNewRelicMetric.attribute.static')) {
const staticAttributes = globals.config.get('Butler.restServerEndpointsConfig.newRelic.postNewRelicMetric.attribute.static');

// eslint-disable-next-line no-restricted-syntax
for (const item of staticAttributes) {
attributes[item.name] = item.value;
if (staticAttributes !== null && staticAttributes.length > 0) {
// eslint-disable-next-line no-restricted-syntax
for (const item of staticAttributes) {
attributes[item.name] = item.value;
}
}
}

Expand Down Expand Up @@ -70,9 +72,11 @@ async function handlerPostNewRelicMetric(request, reply) {
'Api-Key': globals.config.get('Butler.thirdPartyToolsCredentials.newRelic.insertApiKey'),
};

// eslint-disable-next-line no-restricted-syntax
for (const header of globals.config.get('Butler.restServerEndpointsConfig.newRelic.postNewRelicMetric.header')) {
headers[header.name] = header.value;
if (globals.config.get('Butler.restServerEndpointsConfig.newRelic.postNewRelicMetric.header') !== null) {
// eslint-disable-next-line no-restricted-syntax
for (const header of globals.config.get('Butler.restServerEndpointsConfig.newRelic.postNewRelicMetric.header')) {
headers[header.name] = header.value;
}
}

const res = await axios.post(remoteUrl, payload, { headers, timeout: 5000 });
Expand Down

0 comments on commit 81e65ca

Please sign in to comment.