Skip to content

Commit

Permalink
fix: missing isValid bounds check in getWidthHeightInKM is possible u…
Browse files Browse the repository at this point in the history
…ndefined source for vehicleUpdates error
  • Loading branch information
david-abell committed Jun 20, 2024
1 parent cfa4ba2 commit ec91d3e
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 8 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "irish-buses",
"version": "0.14.0",
"version": "0.14.1",
"type": "module",
"scripts": {
"dev": "next dev --experimental-https",
Expand Down
1 change: 1 addition & 0 deletions src/components/Map/MapContentLayer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ function MapContentLayer({

const getWidthHeightInKM = useCallback(() => {
const bounds = map.getBounds();
if (!bounds.isValid()) return 0;

const width =
map.distance(bounds.getNorthWest(), bounds.getNorthEast()) / 1000;
Expand Down
6 changes: 6 additions & 0 deletions src/components/changelog/changelogs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ export type Changelog = {
title?: string;
};
export const changelogs: Changelog[] = [
{
version: "0.14.1",
changes: [
"Possible fix for vehicleUpdates api throwing error when it shouldn't.",
],
},
{
version: "0.14.0",
changes: [
Expand Down
14 changes: 7 additions & 7 deletions src/pages/api/gtfs/vehicle-updates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@ const handler: ApiHandler<VehicleUpdatesResponse> = async (
typeof rad !== "string"
) {
// shouldn't happen
console.error("Shouldn't happen: lat or lng was an array...");
console.error(
`Invalid vehicleUpdates query, expected strings, received: , lat: ${lat}, lng ${lng}, rad ${rad}`,
);
res.status(StatusCodes.BAD_REQUEST).end();
return;
}
Expand Down Expand Up @@ -212,12 +214,10 @@ const handler: ApiHandler<VehicleUpdatesResponse> = async (
// expire after 120 seconds
await redis.expire(GEO_RECORDS_KEY, REDIS_CACHE_EXPIRE_SECONDS);

return res
.status(200)
.json({
vehicleUpdates: vehiclesWithinRadius,
timestamp: String(timestamp),
});
return res.status(200).json({
vehicleUpdates: vehiclesWithinRadius,
timestamp: String(timestamp),
});
} catch (error) {
throw error;
} finally {
Expand Down

0 comments on commit ec91d3e

Please sign in to comment.