Skip to content

Commit 09fde0c

Browse files
committed
Only get statusObj if we have status 200
A non 200 event means there may not be a statusObj, which in turn causes an error which causes a JS jam
1 parent f5dc08e commit 09fde0c

2 files changed

Lines changed: 38 additions & 36 deletions

File tree

lib/ice-coder.js

Lines changed: 34 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1638,27 +1638,28 @@ var ICEcoder = {
16381638
xhr = top.ICEcoder.xhrObj();
16391639
xhr.onreadystatechange=function() {
16401640
if (xhr.readyState==4) {
1641-
// Parse the response as a JSON object
1642-
statusObj = JSON.parse(xhr.responseText);
1641+
// OK reponse?
1642+
if (xhr.status==200) {
1643+
// Parse the response as a JSON object
1644+
statusObj = JSON.parse(xhr.responseText);
16431645

1644-
// Set the action end time and time taken in JSON object
1645-
statusObj.action.timeEnd = new Date().getTime();
1646-
statusObj.action.timeTaken = statusObj.action.timeEnd - statusObj.action.timeStart;
1646+
// Set the action end time and time taken in JSON object
1647+
statusObj.action.timeEnd = new Date().getTime();
1648+
statusObj.action.timeTaken = statusObj.action.timeEnd - statusObj.action.timeStart;
16471649

1648-
// User wanted raw (or both) output of the response?
1649-
if (["raw","both"].indexOf(top.ICEcoder.fileDirResOutput) >= 0) {
1650-
console.log(xhr.responseText);
1651-
}
1652-
// User wanted object (or both) output of the response?
1653-
if (["object","both"].indexOf(top.ICEcoder.fileDirResOutput) >= 0) {
1654-
console.log(statusObj);
1655-
}
1650+
// User wanted raw (or both) output of the response?
1651+
if (["raw","both"].indexOf(top.ICEcoder.fileDirResOutput) >= 0) {
1652+
console.log(xhr.responseText);
1653+
}
1654+
// User wanted object (or both) output of the response?
1655+
if (["object","both"].indexOf(top.ICEcoder.fileDirResOutput) >= 0) {
1656+
console.log(statusObj);
1657+
}
16561658

1657-
// Also store the statusObj
1658-
top.ICEcoder.lastFileDirCheckStatusObj = statusObj;
1659+
// Also store the statusObj
1660+
top.ICEcoder.lastFileDirCheckStatusObj = statusObj;
16591661

1660-
// OK reponse? If error, show that, otherwise do whatever we're required to do next
1661-
if (xhr.status==200) {
1662+
// If error, show that, otherwise do whatever we're required to do next
16621663
if (statusObj.status.error) {
16631664
top.ICEcoder.message(statusObj.status.errorMsg);
16641665
console.log("ICEcoder error info for your request...");
@@ -2546,24 +2547,25 @@ var ICEcoder = {
25462547
xhr = top.ICEcoder.xhrObj();
25472548
xhr.onreadystatechange=function() {
25482549
if (xhr.readyState==4) {
2549-
// Parse the response as a JSON object
2550-
statusObj = JSON.parse(xhr.responseText);
2550+
// OK reponse?
2551+
if (xhr.status==200) {
2552+
// Parse the response as a JSON object
2553+
statusObj = JSON.parse(xhr.responseText);
25512554

2552-
// Set the action end time and time taken in JSON object
2553-
statusObj.action.timeEnd = new Date().getTime();
2554-
statusObj.action.timeTaken = statusObj.action.timeEnd - statusObj.action.timeStart;
2555+
// Set the action end time and time taken in JSON object
2556+
statusObj.action.timeEnd = new Date().getTime();
2557+
statusObj.action.timeTaken = statusObj.action.timeEnd - statusObj.action.timeStart;
25552558

2556-
// User wanted raw (or both) output of the response?
2557-
if (["raw","both"].indexOf(top.ICEcoder.fileDirResOutput) >= 0) {
2558-
console.log(xhr.responseText);
2559-
}
2560-
// User wanted object (or both) output of the response?
2561-
if (["object","both"].indexOf(top.ICEcoder.fileDirResOutput) >= 0) {
2562-
console.log(statusObj);
2563-
}
2559+
// User wanted raw (or both) output of the response?
2560+
if (["raw","both"].indexOf(top.ICEcoder.fileDirResOutput) >= 0) {
2561+
console.log(xhr.responseText);
2562+
}
2563+
// User wanted object (or both) output of the response?
2564+
if (["object","both"].indexOf(top.ICEcoder.fileDirResOutput) >= 0) {
2565+
console.log(statusObj);
2566+
}
25642567

2565-
// OK reponse? If error, show that, otherwise do whatever we're required to do next
2566-
if (xhr.status==200) {
2568+
// If error, show that, otherwise do whatever we're required to do next
25672569
if (statusObj.status.error) {
25682570
top.ICEcoder.message(statusObj.status.errorMsg);
25692571
console.log("ICEcoder error info for your request...");

lib/ice-coder.min.js

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)