Skip to content

Commit

Permalink
fix a couple issues and add some extra logging/error details
Browse files Browse the repository at this point in the history
  • Loading branch information
diosmosis committed Jul 30, 2024
1 parent c790d6c commit 34a7545
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 9 deletions.
6 changes: 5 additions & 1 deletion src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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') || '{}';
Expand Down
2 changes: 1 addition & 1 deletion src/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ export function getSchema(request: GoogleAppsScript.Data_Studio.Request<Connecto

const result = { schema: fields.build() };

debugLog('getSchema(): result is', result);
debugLog('getSchema(): result is', JSON.stringify(result));

return result;
});
Expand Down
6 changes: 5 additions & 1 deletion src/schema/data-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,11 @@ export function convertMatomoTypeToLooker(value: any, matomoType: string) {
return `${value}`;
}

export function mapMatomoAggregationTypeToLooker(matomoAggregation: string): AggregationType|undefined {
export function mapMatomoAggregationTypeToLooker(matomoAggregation?: string): AggregationType|undefined {
if (!matomoAggregation) {
return undefined;
}

switch (matomoAggregation.toLowerCase()) {
case 'avg':
return cc.AggregationType.AVG;
Expand Down
19 changes: 15 additions & 4 deletions src/schema/formula.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,16 +220,27 @@ function toLookerString(ast: MathNode): string {
}
}

export function mapMatomoFormulaToLooker(formula: string): {
lookerFormula: string,
export function mapMatomoFormulaToLooker(formula?: string): {
lookerFormula?: string,
temporaryMetrics: string[],
} {
const ast = math.parse(formula);
if (!formula) {
return {
temporaryMetrics: [],
};
}

let ast;
try {
ast = math.parse(formula);
} catch (e) {
throw new Error(`Failed to parse formula '${formula}': ${e.stack || e.message || e}`);
}

const temporaryMetrics = [];
ast.traverse((node) => {
if (node.type === 'SymbolNode' && (node as SymbolNode).name.startsWith('$')) {
temporaryMetrics.push((node as SymbolNode).name);
temporaryMetrics.push((node as SymbolNode).name.substring(1));
}
});

Expand Down
4 changes: 2 additions & 2 deletions src/schema/report-metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 34a7545

Please sign in to comment.