Skip to content

armgit / TREK

Public Imported from GitHub
0

The most complete open-source travel planner: real-time collaboration, bookings, budgets, packing lists, journals, offline PWA, SSO and an AI-ready MCP server, with planet-wide place search and routing built in.

fix(maps): answer a keyless place lookup with an empty result, not a 400

Mauricec9193e0621fc
diff --git a/server/src/nest/maps/maps.service.ts b/server/src/nest/maps/maps.service.ts
index dc889cea9..efff21f4a 100644
--- a/server/src/nest/maps/maps.service.ts
+++ b/server/src/nest/maps/maps.service.ts
@@ -1545,7 +1545,7 @@ export class MapsService {
placeId: string,
lang?: string,
sessionToken?: string,
- ): Promise<{ place: Record<string, unknown> }> {
+ ): Promise<{ place: Record<string, unknown> | null }> {
// OSM details: placeId is "node:123456" or "way:123456" etc.
if (placeId.includes(':')) {
const [osmType, osmId] = placeId.split(':');
@@ -1584,9 +1584,13 @@ export class MapsService {
// cache rows keyed 'de' for lang-less callers go cold once — 7-day TTL).
const langKey = toApiLang(lang);
const apiKey = this.getMapsKey(userId);
- if (!apiKey) {
- throw Object.assign(new Error('Google Maps API key not configured'), { status: 400 });
- }
+ // No key means no way to resolve a Google id: they have no OpenStreetMap
+ // equivalent to fall back to. That is an empty result, not a client error.
+ // Search and autocomplete already answer their keyless case with the OSM
+ // stack; this used to be the one place that threw instead, which turned an
+ // instance without a key into a stream of 400s whenever an older Google
+ // place was opened. Callers already treat a null place as a miss.
+ if (!apiKey) return { place: null };
// Check DB cache first (lean mask, expanded=0) — 7-day TTL
const DETAILS_TTL = 7 * 24 * 60 * 60 * 1000;
@@ -1681,7 +1685,8 @@ export class MapsService {
const langKey = toApiLang(lang); // 'en' default — see getPlaceDetails
const apiKey = this.getMapsKey(userId);
- if (!apiKey) throw Object.assign(new Error('Google Maps API key not configured'), { status: 400 });
+ // Same as the lean lookup above: an empty result, not a client error.
+ if (!apiKey) return { place: null };
// Check DB cache for expanded result
if (!refresh) {
diff --git a/server/tests/unit/nest/maps.service.test.ts b/server/tests/unit/nest/maps.service.test.ts
index 63b309a5a..6920b189f 100644
--- a/server/tests/unit/nest/maps.service.test.ts
+++ b/server/tests/unit/nest/maps.service.test.ts
@@ -1515,8 +1515,19 @@ describe('getPlaceDetails (fetch stubbed)', () => {
expect((result.place as any).website).toBeNull();
});
- it('MAPS-041: throws 400 when Google placeId given but no API key', async () => {
- await expect(svc.getPlaceDetails(999, 'ChIJNotAnOsmId')).rejects.toMatchObject({ status: 400 });
+ // A Google id has no OpenStreetMap equivalent, so without a key there is
+ // nothing to look up. That is an empty result, not a client error: search and
+ // autocomplete already answer their keyless case with the OSM stack, and this
+ // used to be the one path that threw, so an instance without a key produced a
+ // 400 every time an older Google place was opened.
+ it('MAPS-041: answers with an empty place when a Google id has no API key', async () => {
+ mockDbGet.mockReturnValue(undefined);
+ await expect(svc.getPlaceDetails(999, 'ChIJNotAnOsmId')).resolves.toEqual({ place: null });
+ });
+
+ it('MAPS-041g: the expanded lookup degrades the same way', async () => {
+ mockDbGet.mockReturnValue(undefined);
+ await expect(svc.getPlaceDetailsExpanded(999, 'ChIJNotAnOsmId', 'en', false)).resolves.toEqual({ place: null });
});
it('MAPS-041b: returns full Google place details on happy path', async () => {