Skip to content

Commit

Permalink
Show the return error message instead of undefined when OSRMv1 HTTP r…
Browse files Browse the repository at this point in the history
…equest failed

Fix bug  #510
  • Loading branch information
SuperPat45 authored Feb 5, 2019
1 parent 3916d6a commit d74ab69
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/osrm-v1.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,16 @@
error.message = 'Error parsing OSRM response: ' + ex.toString();
}
} else {
error.message = 'HTTP request failed: ' + err.type +
(err.target && err.target.status ? ' HTTP ' + err.target.status + ': ' + err.target.statusText : '');
var message = err.type + (err.target && err.target.status ? ' HTTP ' + err.target.status + ': ' + err.target.statusText : '');
if (err.responseText) {
try {
data = JSON.parse(err.responseText);
if (data.message)
message = data.message;
} catch (ex) {
}
}
error.message = 'HTTP request failed: ' + message;
error.url = url;
error.status = -1;
error.target = err;
Expand Down

0 comments on commit d74ab69

Please sign in to comment.