From 75cbbceed289e071a599f92f83e3ba32fdf78170 Mon Sep 17 00:00:00 2001 From: Christopher J Lowrie Date: Tue, 28 May 2024 13:32:49 -0700 Subject: [PATCH 1/4] Updating to use local hip service --- README.md | 2 +- frontend/docker-compose.yml | 1 + frontend/src/context/layers/composite_data.ts | 5 ++++- frontend/src/utils/fetch-with-timeout.ts | 13 +++++++++---- 4 files changed, 15 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index a7170e780..051b5eb22 100644 --- a/README.md +++ b/README.md @@ -343,7 +343,7 @@ cd frontend yarn clean yarn install yarn setup:common -REACT_APP_COUNTRY=cambodia yarn start +REACT_APP_COUNTRY=jordan yarn start ``` ### Available Scripts diff --git a/frontend/docker-compose.yml b/frontend/docker-compose.yml index 8aadd6a97..a0945dafa 100644 --- a/frontend/docker-compose.yml +++ b/frontend/docker-compose.yml @@ -8,6 +8,7 @@ services: entrypoint: yarn start environment: - REACT_APP_COUNTRY + - REACT_APP_USE_LOCAL_HIP_SERVICE=http://localhost:3001/q_multi_geojson ports: - "3000:3000" volumes: diff --git a/frontend/src/context/layers/composite_data.ts b/frontend/src/context/layers/composite_data.ts index aa19b22f0..2c844e7a6 100644 --- a/frontend/src/context/layers/composite_data.ts +++ b/frontend/src/context/layers/composite_data.ts @@ -21,7 +21,10 @@ export const fetchCompositeLayerData: LazyLoader = () => as const endDate = new Date(startDate.getTime()); endDate.setMonth(endDate.getMonth() + 1); - const { baseUrl, inputLayers } = layer; + const { baseUrl: _baseUrl, inputLayers } = layer; + const baseUrl = process.env.REACT_APP_USE_LOCAL_HIP_SERVICE + ? process.env.REACT_APP_USE_LOCAL_HIP_SERVICE + : _baseUrl; const { boundingBox } = appConfig.map; // docs: https://hip-service.ovio.org/docs#/default/run_q_multi_geojson_q_multi_geojson_post diff --git a/frontend/src/utils/fetch-with-timeout.ts b/frontend/src/utils/fetch-with-timeout.ts index d6514db18..0ad42a6f8 100644 --- a/frontend/src/utils/fetch-with-timeout.ts +++ b/frontend/src/utils/fetch-with-timeout.ts @@ -29,10 +29,15 @@ export const fetchWithTimeout = async ( signal: controller.signal, }); if (!res.ok) { - throw new HTTPError( - fetchErrorMessage ?? `Something went wrong requesting at ${resource}`, - res.status, - ); + await res.json().then(r => { + console.log(r); + throw new HTTPError( + r.detail ?? + fetchErrorMessage ?? + `Something went wrong requesting at ${resource}`, + res.status, + ); + }); } return res; } catch (error) { From 19203112737f9dd59879b5ef112a5891373a9b15 Mon Sep 17 00:00:00 2001 From: ericboucher Date: Wed, 29 May 2024 13:36:56 +0200 Subject: [PATCH 2/4] no console --- frontend/src/context/layers/composite_data.ts | 1 - frontend/src/utils/fetch-with-timeout.ts | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/src/context/layers/composite_data.ts b/frontend/src/context/layers/composite_data.ts index 2c844e7a6..bee1f1aff 100644 --- a/frontend/src/context/layers/composite_data.ts +++ b/frontend/src/context/layers/composite_data.ts @@ -16,7 +16,6 @@ export const fetchCompositeLayerData: LazyLoader = () => as // to complete later with new endpoint for composite chart const { layer, date } = params; - console.log(date); const startDate = date ? new Date(date) : new Date(); const endDate = new Date(startDate.getTime()); endDate.setMonth(endDate.getMonth() + 1); diff --git a/frontend/src/utils/fetch-with-timeout.ts b/frontend/src/utils/fetch-with-timeout.ts index 0ad42a6f8..d533a8d0f 100644 --- a/frontend/src/utils/fetch-with-timeout.ts +++ b/frontend/src/utils/fetch-with-timeout.ts @@ -30,6 +30,7 @@ export const fetchWithTimeout = async ( }); if (!res.ok) { await res.json().then(r => { + // eslint-disable-next-line no-console console.log(r); throw new HTTPError( r.detail ?? From 20450e7a33ea5c30036ab3b15ee57d913a680a8c Mon Sep 17 00:00:00 2001 From: Will Gislason <8203830+gislawill@users.noreply.github.com> Date: Tue, 2 Jul 2024 13:13:31 -0500 Subject: [PATCH 3/4] Clean up --- frontend/src/utils/error-utils.ts | 2 ++ frontend/src/utils/fetch-with-timeout.ts | 18 ++++++++---------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/frontend/src/utils/error-utils.ts b/frontend/src/utils/error-utils.ts index 4ec325566..fd19233f2 100644 --- a/frontend/src/utils/error-utils.ts +++ b/frontend/src/utils/error-utils.ts @@ -15,7 +15,9 @@ export class HTTPError extends Error { constructor( public readonly message: string, public readonly statusCode: number, + public readonly detail?: string, ) { super(message); + console.error('New HTTP Error: ', { message, statusCode, detail }); } } diff --git a/frontend/src/utils/fetch-with-timeout.ts b/frontend/src/utils/fetch-with-timeout.ts index d533a8d0f..f551f539d 100644 --- a/frontend/src/utils/fetch-with-timeout.ts +++ b/frontend/src/utils/fetch-with-timeout.ts @@ -29,16 +29,14 @@ export const fetchWithTimeout = async ( signal: controller.signal, }); if (!res.ok) { - await res.json().then(r => { - // eslint-disable-next-line no-console - console.log(r); - throw new HTTPError( - r.detail ?? - fetchErrorMessage ?? - `Something went wrong requesting at ${resource}`, - res.status, - ); - }); + const body = await res.json(); + throw new HTTPError( + body.detail ?? + fetchErrorMessage ?? + `Something went wrong requesting at ${resource}`, + res.status, + body, + ); } return res; } catch (error) { From d61911f7ccb8cbb93ab28ea9259f1816e66829c1 Mon Sep 17 00:00:00 2001 From: Will Gislason <8203830+gislawill@users.noreply.github.com> Date: Tue, 2 Jul 2024 13:14:32 -0500 Subject: [PATCH 4/4] Clean up readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 210fb9c40..a7170e780 100644 --- a/README.md +++ b/README.md @@ -343,7 +343,7 @@ cd frontend yarn clean yarn install yarn setup:common -REACT_APP_COUNTRY=jordan REACT_APP_USE_LOCAL_HIP_SERVICE=http://localhost:3001/q_multi_geojson docker compose up +REACT_APP_COUNTRY=cambodia yarn start ``` ### Available Scripts