From 34a7545da9b20b9b15365de31b54abfc6352385d Mon Sep 17 00:00:00 2001 From: diosmosis Date: Mon, 29 Jul 2024 18:13:28 -0700 Subject: [PATCH] fix a couple issues and add some extra logging/error details --- src/api.ts | 6 +++++- src/data.ts | 2 +- src/schema/data-types.ts | 6 +++++- src/schema/formula.ts | 19 +++++++++++++++---- src/schema/report-metadata.ts | 4 ++-- 5 files changed, 28 insertions(+), 9 deletions(-) diff --git a/src/api.ts b/src/api.ts index f7d27df..688b6ea 100644 --- a/src/api.ts +++ b/src/api.ts @@ -207,10 +207,14 @@ export function fetchAll(requests: MatomoRequestParams[], options: ApiFetchOptio return; // retry } + const content = r.getContentText('UTF-8'); + responseContents[responseIndex] = { result: 'error', - message: `Matomo server failed with code ${code}. Truncated response: ${r.getContentText('UTF-8').substring(0, 100)}`, + message: `Matomo server failed with code ${code}. Truncated response: ${content.substring(0, 100)}`, }; + + debugLog(`Whole response: ${content}`); } else { // save the response even if it's an error so we can get the server-side error message if needed responseContents[responseIndex] = r.getContentText('UTF-8') || '{}'; diff --git a/src/data.ts b/src/data.ts index d8564a8..37029b8 100644 --- a/src/data.ts +++ b/src/data.ts @@ -201,7 +201,7 @@ export function getSchema(request: GoogleAppsScript.Data_Studio.Request { if (node.type === 'SymbolNode' && (node as SymbolNode).name.startsWith('$')) { - temporaryMetrics.push((node as SymbolNode).name); + temporaryMetrics.push((node as SymbolNode).name.substring(1)); } }); diff --git a/src/schema/report-metadata.ts b/src/schema/report-metadata.ts index de68086..f6e0cee 100644 --- a/src/schema/report-metadata.ts +++ b/src/schema/report-metadata.ts @@ -277,8 +277,8 @@ export function getFieldsFromReportMetadata( }); allTemporaryMetrics.forEach((metricId) => { - const aggregationType = reportMetadata.temporaryMetricAggregationTypes[metricId]; - const matomoType = reportMetadata.temporaryMetricSemanticTypes[metricId]; + const aggregationType = reportMetadata.temporaryMetricAggregationTypes?.[metricId]; + const matomoType = reportMetadata.temporaryMetricSemanticTypes?.[metricId]; if (!matomoType) { return;