From e819ade8cb35d0c12a366f6d936d49e40e18bfbf Mon Sep 17 00:00:00 2001 From: mattwr18 Date: Mon, 9 Sep 2019 09:54:38 +0200 Subject: [PATCH 1/3] Add console.log statement on error to help debug - Geolocation is working in development, but not on staging or production --- webapp/pages/settings/index.vue | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/webapp/pages/settings/index.vue b/webapp/pages/settings/index.vue index 4ad57b49c..eb6fbbd33 100644 --- a/webapp/pages/settings/index.vue +++ b/webapp/pages/settings/index.vue @@ -159,7 +159,6 @@ export default { this.cities = [] return } - this.loadingGeo = true this.axiosSource = CancelToken.source() @@ -176,6 +175,10 @@ export default { .then(res => { this.cities = this.processCityResults(res) }) + .catch(error => { + /* eslint-disable-next-line no-console */ + console.log(error) + }) .finally(() => { this.loadingGeo = false }) From 2aef2add3d228b0381c1e23685f458df842b8e08 Mon Sep 17 00:00:00 2001 From: mattwr18 Date: Mon, 9 Sep 2019 12:53:47 +0200 Subject: [PATCH 2/3] 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 }) From d3952e2adaf50cac7c107bf0dad3a46a77eecf6b Mon Sep 17 00:00:00 2001 From: mattwr18 Date: Mon, 9 Sep 2019 14:32:01 +0200 Subject: [PATCH 3/3] Use debug npm package over console.log - @roschaefer `PR` review - better because we can leave in the code base and show only when/if we want to --- backend/src/middleware/nodes/locations.js | 28 +++++++++++------------ 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/backend/src/middleware/nodes/locations.js b/backend/src/middleware/nodes/locations.js index 8a11d8e55..a90d8c0d7 100644 --- a/backend/src/middleware/nodes/locations.js +++ b/backend/src/middleware/nodes/locations.js @@ -1,9 +1,12 @@ import request from 'request' import { UserInputError } from 'apollo-server' import isEmpty from 'lodash/isEmpty' +import Debug from 'debug' import asyncForEach from '../../helpers/asyncForEach' import CONFIG from './../../config' +const debug = Debug('human-connection:location') + const fetch = url => { return new Promise((resolve, reject) => { request(url, function(error, response, body) { @@ -59,21 +62,16 @@ const createOrUpdateLocations = async (userId, locationName, driver) => { if (isEmpty(locationName)) { return } - 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) - } + + 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( + ',', + )}`, + ) + + debug(res) if (!res || !res.features || !res.features[0]) { throw new UserInputError('locationName is invalid')