From df0e1d3d0f066d8acdf1b53e296d7814bac18a72 Mon Sep 17 00:00:00 2001 From: Brendan Chen Date: Wed, 22 Jan 2025 14:59:04 -0800 Subject: [PATCH] add error throwing to method --- src/loaders/ApiBasedRepositoryLoader.ts | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/src/loaders/ApiBasedRepositoryLoader.ts b/src/loaders/ApiBasedRepositoryLoader.ts index 031d30b..f9f740d 100644 --- a/src/loaders/ApiBasedRepositoryLoader.ts +++ b/src/loaders/ApiBasedRepositoryLoader.ts @@ -120,15 +120,21 @@ export class ApiBasedRepositoryLoader { formData.set("json", JSON.stringify(formDataJsonObject)); const query = new URLSearchParams(params).toString(); - const response = await fetch(`${this.baseUrl}?${query}`, { - method: "POST", - body: formData, - }); - const json = await response.json(); - await this.updateStopDataForSystemAndApiResponse(systemId, json); - await this.updateOrderedStopDataForExistingStops(json); - await this.updatePolylineDataForExistingRoutesAndApiResponse(json); + try { + const response = await fetch(`${this.baseUrl}?${query}`, { + method: "POST", + body: formData, + }); + const json = await response.json(); + + await this.updateStopDataForSystemAndApiResponse(systemId, json); + await this.updateOrderedStopDataForExistingStops(json); + await this.updatePolylineDataForExistingRoutesAndApiResponse(json); + } catch(e: any) { + console.error(`fetchAndUpdateStopAndPolylineDataForRoutesWithSystemId failed for system ID ${systemId}:`, e); + throw new ApiResponseError(e.message); + } } public async fetchAndUpdateShuttleDataForExistingSystems() {