mirror of
https://github.com/brendan-ch/project-inter-server.git
synced 2026-04-17 07:50:31 +00:00
update fetchAndUpdateRouteDataForSystemId to include try/catch
This commit is contained in:
@@ -71,24 +71,30 @@ export class ApiBasedRepositoryLoader {
|
|||||||
formData.set("json", JSON.stringify(formDataJsonObject));
|
formData.set("json", JSON.stringify(formDataJsonObject));
|
||||||
|
|
||||||
const query = new URLSearchParams(params).toString();
|
const query = new URLSearchParams(params).toString();
|
||||||
const response = await fetch(`${this.baseUrl}?${query}`, {
|
|
||||||
method: "POST",
|
|
||||||
body: formData,
|
|
||||||
});
|
|
||||||
const json = await response.json();
|
|
||||||
|
|
||||||
if (typeof json.all === "object") {
|
try {
|
||||||
await Promise.all(json.all.map(async (jsonRoute: any) => {
|
const response = await fetch(`${this.baseUrl}?${query}`, {
|
||||||
const constructedRoute: IRoute = {
|
method: "POST",
|
||||||
name: jsonRoute.name,
|
body: formData,
|
||||||
color: jsonRoute.color,
|
});
|
||||||
id: jsonRoute.myid,
|
const json = await response.json();
|
||||||
polylineCoordinates: [],
|
|
||||||
systemId: systemId,
|
|
||||||
};
|
|
||||||
|
|
||||||
await this.repository.addOrUpdateRoute(constructedRoute);
|
if (typeof json.all === "object") {
|
||||||
}))
|
await Promise.all(json.all.map(async (jsonRoute: any) => {
|
||||||
|
const constructedRoute: IRoute = {
|
||||||
|
name: jsonRoute.name,
|
||||||
|
color: jsonRoute.color,
|
||||||
|
id: jsonRoute.myid,
|
||||||
|
polylineCoordinates: [],
|
||||||
|
systemId: systemId,
|
||||||
|
};
|
||||||
|
|
||||||
|
await this.repository.addOrUpdateRoute(constructedRoute);
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
} catch(e: any) {
|
||||||
|
console.error(`fetchAndUpdateRouteDataForSystemId failed for system ID ${systemId}: ${e}`);
|
||||||
|
throw new ApiResponseError(e.message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user