Skip to content

Commit

Permalink
Improving error handling (#324)
Browse files Browse the repository at this point in the history
  • Loading branch information
charly22 authored Feb 1, 2022
1 parent bfefe65 commit 434c517
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
1 change: 1 addition & 0 deletions .jshintrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"esversion": 9,
"node": true,
"globals": {"describe" : true, "it" : true}
}
4 changes: 4 additions & 0 deletions lib/geocoder/heregeocoder.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const AbstractGeocoder = require('./abstractgeocoder');
const ValueError = require('./../error/valueerror');

const OPTIONS = [
'apiKey',
Expand Down Expand Up @@ -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);
Expand Down
12 changes: 10 additions & 2 deletions lib/httpadapter/fetchadapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
});
Expand Down

0 comments on commit 434c517

Please sign in to comment.