This PR removes the double conversion of JSON strings from the request response to ARCGIS queries.
It also updates it's tests to a valid-passing status.
Why
Running the example:
import NodeGeocoder from 'node-geocoder';
import { ARCGIS_CLIENT_ID, ARCGIS_CLIENT_SECRET } from './config';
var options: NodeGeocoder.AgolOptions = {
provider: 'agol',
client_id: ARCGIS_CLIENT_ID,
client_secret: ARCGIS_CLIENT_SECRET,
};
var geocoder = NodeGeocoder(options);
// Using callback
geocoder.geocode('29 champs elysée paris', function(err: any, res: any) {
console.log(res);
});
// Or using Promise
geocoder
.geocode('29 champs elysée paris')
.then(function(res: any) {
console.log(res);
})
.catch(function(err: any) {
console.log(err);
});
Throws error
SyntaxError: Unexpected token o in JSON at position 1
at JSON.parse (<anonymous>)
at C:\Users\USERNAME\ra-map\node_modules\node-geocoder\lib\geocoder\agolgeocoder.js:122:21
at IncomingMessage.<anonymous> (C:\Users\jaepe\ra-map\node_modules\node-geocoder\lib\httpadapter\httpadapter.js:66:9)
at IncomingMessage.emit (events.js:185:15)
at IncomingMessage.emit (domain.js:421:20)
at endReadableNT (_stream_readable.js:1106:12)
at process._tickCallback (internal/process/next_tick.js:114:19)
Which is caused by:
lib\geocoder\agolgeocoder.js
_this.httpAdapter.get(_this._endpoint, params, function(err, result) {
result = JSON.parse(result);
What
This PR removes the double conversion of JSON strings from the request response to ARCGIS queries. It also updates it's tests to a valid-passing status.
Why
Running the example:
Throws error
Which is caused by:
lib\geocoder\agolgeocoder.js
And
lib\httpadapter\httpadapter.js
Which is due to the header response from ARCGIS:
'content-type': 'application/json;