node-geocoder icon indicating copy to clipboard operation
node-geocoder copied to clipboard

agolgeocoder crashing application when using invalid client and secret key instead of throwing exception

Open juliano-aiqfome opened this issue 1 year ago • 1 comments

in the file node-geocoder/lib/geocoder/agolgeocoder.js:86:21, when agolgeocoder returns an error, the variable result receives a json object format, as the example below: { error: { code: 400, error: 'invalid_client_id', error_description: 'Invalid client_id', message: 'Invalid client_id', details: [] } } but, the code tries to parse the object to json again, resulting on the following error: ` /app/node_modules/bluebird/js/release/async.js:49 fn = function () { throw arg; }; ^

SyntaxError: "[object Object]" is not valid JSON at JSON.parse () at /app/node_modules/node-geocoder/lib/geocoder/agolgeocoder.js:86:21 at tryCatcher (/app/node_modules/bluebird/js/release/util.js:16:23) at Promise.successAdapter [as _fulfillmentHandler0] (/app/node_modules/bluebird/js/release/nodeify.js:23:30) at Promise._settlePromise (/app/node_modules/bluebird/js/release/promise.js:601:21) at Promise._settlePromise0 (/app/node_modules/bluebird/js/release/promise.js:649:10) at Promise._settlePromises (/app/node_modules/bluebird/js/release/promise.js:729:18) at _drainQueueStep (/app/node_modules/bluebird/js/release/async.js:93:12) at _drainQueue (/app/node_modules/bluebird/js/release/async.js:86:9) at Async._drainQueues (/app/node_modules/bluebird/js/release/async.js:102:5) at Async.drainQueues (/app/node_modules/bluebird/js/release/async.js:15:14) at process.processImmediate (node:internal/timers:483:21) `

a possible fix would be parse the response to json only if it's of the type string, something like: if (typeof result === 'string') { result = JSON.parse(result); }

what do you think?

juliano-aiqfome avatar Sep 24 '24 20:09 juliano-aiqfome

Yes it will be better, do you think you could come with a PR to fix that?

nchaulet avatar Oct 20 '24 22:10 nchaulet

I can verify this error, but it appears to occur with even valid credentials as the token results are already parsed.

Note: access token in screen cap has already been invalidated. image

rveitch avatar Oct 30 '24 18:10 rveitch

Ok @nchaulet , I will create a new PR

juliano-aiqfome avatar Nov 11 '24 19:11 juliano-aiqfome