diff --git a/server/src/routes/geojsonRoutes.ts b/server/src/routes/geojsonRoutes.ts index 639f56ef2..50fbf96d6 100644 --- a/server/src/routes/geojsonRoutes.ts +++ b/server/src/routes/geojsonRoutes.ts @@ -18,17 +18,24 @@ router.get( params.resourceId, ); + if (!object) { + return ctx.json( + { + error: `Resource ${params.resource}/${params.resourceId} not found`, + }, + 404, + ); + } + const headers = new Headers(); object.writeHttpMetadata(headers); - headers.set('etag', object.httpEtag); - headers.set('Content-Type', 'application/geo+json'); + ctx.header('etag', object.httpEtag); + ctx.header('Content-Type', 'application/geo+json'); const json = await object.json(); - return new Response(json, { - headers, - }); + return ctx.json(json); } catch (error) { - return ctx.json({ error: error.message }, 400); + return ctx.json({ error: error.message }, 500); } }), ); diff --git a/server/src/services/geojsonStorage/index.ts b/server/src/services/geojsonStorage/index.ts index 4381e3808..73d1ad759 100644 --- a/server/src/services/geojsonStorage/index.ts +++ b/server/src/services/geojsonStorage/index.ts @@ -23,16 +23,14 @@ export class GeojsonStorageService { resource: ResourceType, geojson: string, resourceId: string, - ): Promise { - const object = await this._bucket.put(`${resource}/${resourceId}`, geojson); - return object; + ): Promise { + return this._bucket.put(`${resource}/${resourceId}`, geojson); } public static async retrieve( resource: ResourceType, resourceId: string, - ): Promise { - const object = await this._bucket.get(`${resource}/${resourceId}`); - return object; + ): Promise { + return this._bucket.get(`${resource}/${resourceId}`); } } diff --git a/server/src/services/trip/editTripService.ts b/server/src/services/trip/editTripService.ts index c9f1d669a..8aea90452 100644 --- a/server/src/services/trip/editTripService.ts +++ b/server/src/services/trip/editTripService.ts @@ -37,6 +37,7 @@ export const editTripService = async ( await scoreTripService(selectedTrip.id); const serializedGeoJSON = tripData.geoJSON; + if (!serializedGeoJSON) { return updatedTrip; }