chore: :loud_sound: Improve logging
Tim Izzo tim@octree.ch
Thu, 20 Mar 2025 15:13:33 +0100
3 files changed,
14 insertions(+),
13 deletions(-)
M
backend/src/graphql/event/event.ts
→
backend/src/graphql/event/event.ts
@@ -70,6 +70,7 @@ const { uuid } = args;
const event = await strapi.db .query("api::event.event") .findOne({ where: { uuid } }); + strapi.log.warn(`No event found for uuid ${uuid}`); if (!event) throw new Error("No matching event"); const { toEntityResponse } = strapi .plugin("graphql")
M
frontend/lib/apolloClient.ts
→
frontend/lib/apolloClient.ts
@@ -6,6 +6,7 @@ import merge from 'deepmerge';
import isEqual from 'lodash/isEqual'; import {signOut, useSession} from 'next-auth/react'; +const ENV = process.env.NODE_ENV; export const APOLLO_STATE_PROP_NAME = '__APOLLO_STATE__'; let apolloClient: ApolloClient<any>;@@ -21,7 +22,7 @@ };
}); const errorLink = onError(({operation, networkError, response}) => { - console.error({networkError, operation}); + if (ENV !== 'production') console.error({networkError, operation}); if (response) console.error(JSON.stringify(response, null, 4)); const responseStatus = networkError?.response?.status;
M
frontend/pages/api/mapbox/places.ts
→
frontend/pages/api/mapbox/places.ts
@@ -18,19 +18,18 @@
const url = `${MAPBOX_URL}geocoding/v5/mapbox.places/${search}.json?proximity=${proximity}&access_token=${MAPBOX_TOKEN}&language=${locale}`; try { - const mapBoxResult = await fetch(url).then(response => { - if (response.status === 429) - throw new Error('MAPBOX_RATE_LIMIT_EXCEEDED'); - else if (response.status === 401) throw new Error('MAPBOX_UNAUTHORIZED'); - return response.json(); - }); - - if (mapBoxResult?.features) { - res.status(200).send(mapBoxResult.features); - return; - } else throw new Error('MAPBOX_MALFORMED_RESPONSE'); + const response = await fetch(url); + if (response.status === 429) throw new Error('MAPBOX_RATE_LIMIT_EXCEEDED'); + else if (response.status === 401) throw new Error('MAPBOX_UNAUTHORIZED'); + const mapBoxResult = await response.json(); + if (mapBoxResult?.features) + return res.status(200).send(mapBoxResult.features); + else { + console.warn('MALFORMED RESPONSE FROM MAPBOX', mapBoxResult); + throw new Error('MAPBOX_MALFORMED_RESPONSE'); + } } catch (error) { - console.error(error); + console.error('ERROR WITH MAPBOX: ', error.message); res.status(500); } }