mirror of
https://github.com/brendan-ch/project-inter-server.git
synced 2026-04-19 08:50:29 +00:00
add try/catch to remaining methods
This commit is contained in:
@@ -156,31 +156,36 @@ 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 (json.buses && json.buses["-1"] === undefined) {
|
try {
|
||||||
const jsonBuses = Object.values(json.buses).map((busesArr: any) => {
|
const response = await fetch(`${this.baseUrl}?${query}`, {
|
||||||
return busesArr[0];
|
method: "POST",
|
||||||
|
body: formData,
|
||||||
});
|
});
|
||||||
|
const json = await response.json();
|
||||||
|
|
||||||
await Promise.all(jsonBuses.map(async (jsonBus: any) => {
|
if (json.buses && json.buses["-1"] === undefined) {
|
||||||
const constructedShuttle: IShuttle = {
|
const jsonBuses = Object.values(json.buses).map((busesArr: any) => {
|
||||||
name: jsonBus.bus,
|
return busesArr[0];
|
||||||
coordinates: {
|
});
|
||||||
latitude: parseFloat(jsonBus.latitude),
|
|
||||||
longitude: parseFloat(jsonBus.longitude),
|
|
||||||
},
|
|
||||||
routeId: jsonBus.routeId,
|
|
||||||
systemId: systemId,
|
|
||||||
id: `${jsonBus.busId}`
|
|
||||||
}
|
|
||||||
|
|
||||||
await this.repository.addOrUpdateShuttle(constructedShuttle);
|
await Promise.all(jsonBuses.map(async (jsonBus: any) => {
|
||||||
}))
|
const constructedShuttle: IShuttle = {
|
||||||
|
name: jsonBus.bus,
|
||||||
|
coordinates: {
|
||||||
|
latitude: parseFloat(jsonBus.latitude),
|
||||||
|
longitude: parseFloat(jsonBus.longitude),
|
||||||
|
},
|
||||||
|
routeId: jsonBus.routeId,
|
||||||
|
systemId: systemId,
|
||||||
|
id: `${jsonBus.busId}`
|
||||||
|
}
|
||||||
|
|
||||||
|
await this.repository.addOrUpdateShuttle(constructedShuttle);
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
} catch(e: any) {
|
||||||
|
throw new ApiResponseError(e.message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -207,26 +212,31 @@ export class ApiBasedRepositoryLoader {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const query = new URLSearchParams(params).toString();
|
const query = new URLSearchParams(params).toString();
|
||||||
const response = await fetch(`${this.baseUrl}?${query}`, {
|
|
||||||
method: "GET",
|
|
||||||
});
|
|
||||||
const json = await response.json();
|
|
||||||
|
|
||||||
if (json.ETAs && json.ETAs[stopId]) {
|
try {
|
||||||
// Continue with the parsing
|
const response = await fetch(`${this.baseUrl}?${query}`, {
|
||||||
json.ETAs[stopId].forEach((jsonEta: any) => {
|
method: "GET",
|
||||||
// Update cache
|
|
||||||
const shuttleId: string = jsonEta.busId;
|
|
||||||
|
|
||||||
const eta: IEta = {
|
|
||||||
secondsRemaining: jsonEta.secondsSpent,
|
|
||||||
shuttleId: `${shuttleId}`,
|
|
||||||
stopId: stopId,
|
|
||||||
millisecondsSinceEpoch: Date.now(),
|
|
||||||
};
|
|
||||||
|
|
||||||
this.repository.addOrUpdateEta(eta);
|
|
||||||
});
|
});
|
||||||
|
const json = await response.json();
|
||||||
|
|
||||||
|
if (json.ETAs && json.ETAs[stopId]) {
|
||||||
|
// Continue with the parsing
|
||||||
|
json.ETAs[stopId].forEach((jsonEta: any) => {
|
||||||
|
// Update cache
|
||||||
|
const shuttleId: string = jsonEta.busId;
|
||||||
|
|
||||||
|
const eta: IEta = {
|
||||||
|
secondsRemaining: jsonEta.secondsSpent,
|
||||||
|
shuttleId: `${shuttleId}`,
|
||||||
|
stopId: stopId,
|
||||||
|
millisecondsSinceEpoch: Date.now(),
|
||||||
|
};
|
||||||
|
|
||||||
|
this.repository.addOrUpdateEta(eta);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} catch(e: any) {
|
||||||
|
throw new ApiResponseError(e.message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user