diff --git a/.jshintrc b/.jshintrc index 20f2d4c6..f494c6e0 100644 --- a/.jshintrc +++ b/.jshintrc @@ -1,4 +1,5 @@ { + "esversion": 9, "node": true, "globals": {"describe" : true, "it" : true} } \ No newline at end of file diff --git a/lib/geocoder/heregeocoder.js b/lib/geocoder/heregeocoder.js index bb76fd9d..0eeb01f7 100644 --- a/lib/geocoder/heregeocoder.js +++ b/lib/geocoder/heregeocoder.js @@ -1,4 +1,5 @@ const AbstractGeocoder = require('./abstractgeocoder'); +const ValueError = require('./../error/valueerror'); const OPTIONS = [ 'apiKey', @@ -71,6 +72,9 @@ class HereGeocoder extends AbstractGeocoder { if (err) { return callback(err, results); } else { + if (result.type === 'ApplicationError') { + return callback(new ValueError(result.Details), results); + } var view = result.Response.View[0]; if (!view) { return callback(false, results); diff --git a/lib/httpadapter/fetchadapter.js b/lib/httpadapter/fetchadapter.js index 2e07119b..fafcbe0c 100644 --- a/lib/httpadapter/fetchadapter.js +++ b/lib/httpadapter/fetchadapter.js @@ -39,11 +39,19 @@ class FetchAdapter { url + '?' + querystring.encode(params), options ); - + const contentType = res.headers.get('content-type'); + if (!contentType || contentType.indexOf('application/json') === -1) { + throw new HttpError(await res.text(), { + code: res.statusCode + }); + } return res.json(); }) .catch(function(error) { - var _error = error.cause ? error.cause : error; + if (error instanceof HttpError) { + throw error; + } + const _error = error.cause ? error.cause : error; throw new HttpError(_error.message, { code: _error.code });