Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

modified exception handler to resolve similar to request.timeout #18

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 25 additions & 7 deletions src/main/resources/static/js/tile.js
Original file line number Diff line number Diff line change
Expand Up @@ -892,7 +892,20 @@
Rx.Observable.fromPromise(postWithCancel(url, tokenForSummary, geometry))
.subscribe(function (response){
console.log(response);
features.innerHTML = "<b>Result of the querying polgon(s):</b><br/>" + JSON.stringify(JSON.parse(response), null, 2);

try {
features.innerHTML = "<b>Result of the querying polgon(s):</b><br/>" + JSON.stringify(JSON.parse(response), null, 2);
}
catch(exception){
Copy link
Contributor Author

@TerenceSperringerJr TerenceSperringerJr Feb 14, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in theory this catch should never hit since we now reformat exceptions prior to resolve()

but if something was passed that wasn't an exception but still didn't parse correctly within resolve(), this will let us know what happened

var k;
features.innerHTML = "<b>" + exception + "</b><br/>";

for(k in response) {
if(response.hasOwnProperty(k)) {
features.innerHTML += k + ": " + response[k] + "<br>";
}
}
}
});
}
else {
Expand Down Expand Up @@ -1029,7 +1042,7 @@

request.open(method, url);

if (body){
if(body) {
request.setRequestHeader('Content-Type', 'application/json;charset=UTF-8');
body = JSON.stringify(body);
}
Expand All @@ -1038,6 +1051,9 @@

return new Promise(
function (resolve, reject) {
request.onerror = reject;
request.timeout = request.onerror;

request.onload = function () {
var parsedResponse,
k;
Expand All @@ -1056,18 +1072,20 @@

resolve(JSON.stringify(parsedResponse));
}
catch(err) {
resolve(err + "<br>" + request.responseText);
catch(exception) {
resolve(JSON.stringify({
"path": request.responseURL,
"status": request.status,
"error": request.statusText,
"message": request.responseText
}));
}
};

token.cancel = function () {
request.abort();
reject(new Error('Cancelled')); // reject the promise
};

request.onerror = reject;
request.timeout = reject;//(request.statusText);
}
);
}
Expand Down