From 0463d019fc5b41877b83f64fa642b8da5e57274c Mon Sep 17 00:00:00 2001 From: edlu77 Date: Mon, 22 Apr 2024 12:42:25 -0400 Subject: [PATCH] Make public if aggregate-table-json is empty --- .../dataset-loader/dataset-loader.service.ts | 4 ++++ apps/a2agc/src/app/core/state/data/data.state.ts | 16 +--------------- 2 files changed, 5 insertions(+), 15 deletions(-) diff --git a/apps/a2agc/src/app/core/services/dataset-loader/dataset-loader.service.ts b/apps/a2agc/src/app/core/services/dataset-loader/dataset-loader.service.ts index 32a7d0a..8291a5d 100644 --- a/apps/a2agc/src/app/core/services/dataset-loader/dataset-loader.service.ts +++ b/apps/a2agc/src/app/core/services/dataset-loader/dataset-loader.service.ts @@ -100,6 +100,10 @@ export class DatasetLoaderService { * @returns parsed results */ private parseRawData(data: RawData): ParseResults { + if (!data) { + return { datasets: [], variables: [] }; + } + const datasets: Dataset[] = []; const variables: DatasetVariable[] = []; diff --git a/apps/a2agc/src/app/core/state/data/data.state.ts b/apps/a2agc/src/app/core/state/data/data.state.ts index abc5a48..f047fc0 100644 --- a/apps/a2agc/src/app/core/state/data/data.state.ts +++ b/apps/a2agc/src/app/core/state/data/data.state.ts @@ -58,7 +58,7 @@ export class DataState extends NgxsImmutableDataRepository { isPrivate(): Observable { const response = this.http.get(DATA_CONFIG.datasetsPath); return response.pipe( - map((result) => this.isValidJson(result)), + map((result) => !!result), catchError(this.handleError) ); } @@ -70,18 +70,4 @@ export class DataState extends NgxsImmutableDataRepository { private handleError(): Observable { return of(false); } - - /** - * Checks if string is valid json - * @param input string - * @returns true if valid json - */ - private isValidJson(input: string): boolean { - try { - JSON.parse(input); - return true; - } catch { - return false; - } - } }