From d3952e2adaf50cac7c107bf0dad3a46a77eecf6b Mon Sep 17 00:00:00 2001 From: mattwr18 Date: Mon, 9 Sep 2019 14:32:01 +0200 Subject: [PATCH] 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')