From 2aef2add3d228b0381c1e23685f458df842b8e08 Mon Sep 17 00:00:00 2001 From: mattwr18 Date: Mon, 9 Sep 2019 12:53:47 +0200 Subject: [PATCH] Add temporarily console.log statements to debug failed API call - in production environment, the user locationName is updated, but it is failing the `createOrUpdateLocations` function in backend/src/middleware/nodes/locations.js For some reason, it seems like the API call is coming back with something other than what we are looking for. Need help debugging... we can remove this code after we figure out what's wrong --- backend/src/middleware/nodes/locations.js | 22 +++++++++++++++------- webapp/pages/settings/index.vue | 6 +----- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/backend/src/middleware/nodes/locations.js b/backend/src/middleware/nodes/locations.js index d7abb90ff..8a11d8e55 100644 --- a/backend/src/middleware/nodes/locations.js +++ b/backend/src/middleware/nodes/locations.js @@ -59,13 +59,21 @@ const createOrUpdateLocations = async (userId, locationName, driver) => { if (isEmpty(locationName)) { return } - const res = await fetch( - `https://api.mapbox.com/geocoding/v5/mapbox.places/${encodeURIComponent( - locationName, - )}.json?access_token=${CONFIG.MAPBOX_TOKEN}&types=region,place,country&language=${locales.join( - ',', - )}`, - ) + let res + try { + res = await fetch( + `https://api.mapbox.com/geocoding/v5/mapbox.places/${encodeURIComponent( + locationName, + )}.json?access_token=${ + CONFIG.MAPBOX_TOKEN + }&types=region,place,country&language=${locales.join(',')}`, + ) + /* eslint-disable-next-line no-console */ + console.log('res', res) + } catch (error) { + /* eslint-disable-next-line no-console */ + console.log('error', error) + } if (!res || !res.features || !res.features[0]) { throw new UserInputError('locationName is invalid') diff --git a/webapp/pages/settings/index.vue b/webapp/pages/settings/index.vue index eb6fbbd33..5c99f4b8b 100644 --- a/webapp/pages/settings/index.vue +++ b/webapp/pages/settings/index.vue @@ -101,7 +101,7 @@ export default { async submit() { this.loadingData = true const { name, about } = this.formData - let { locationName } = this.formData + let { locationName } = this.formData || this.currentUser locationName = locationName && (locationName['label'] || locationName) try { await this.$apollo.mutate({ @@ -175,10 +175,6 @@ export default { .then(res => { this.cities = this.processCityResults(res) }) - .catch(error => { - /* eslint-disable-next-line no-console */ - console.log(error) - }) .finally(() => { this.loadingGeo = false })