How to capture Java script https request exception/error?

102 views
Skip to first unread message

Harry Lee

unread,
Aug 24, 2016, 5:41:51 PM8/24/16
to chromi...@chromium.org
Hi, my Chrome app tries to make a XMLHttpRequest and got an error/exception.

Manually inspect the page console, see that this error printed out:

POST https://x.y.z net::ERR_INSECURE_RESPONSE

I want to capture this error/ exception from my Java Script program and have tried different methods:

window.onerror = function(errMsg .......) {}

window.addEventListener("error" .....)

redirect console error to my own function s.th. like
window.console.error = myFunc;
function myFunc(msg) {
     //do something with msg
}

None of them works, neither try/catch.

You help would be much appreciated.

H

PhistucK

unread,
Aug 25, 2016, 12:49:30 PM8/25/16
to Harry Lee, Chromium Apps
Just set up an event listener on your XMLHttpRequest instance.
var foo = new XMLHttpRequest();
foo.onerror =
 function ()
 {
  console.log("Error loading stuff");
 }​;
// The rest of your code...
​​
Or am I missing something?


PhistucK

--
You received this message because you are subscribed to the Google Groups "Chromium-Apps-Announce" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-apps+unsubscribe@chromium.org.
To post to this group, send email to chromi...@chromium.org.
Visit this group at https://groups.google.com/a/chromium.org/group/chromium-apps/.
For more options, visit https://groups.google.com/a/chromium.org/d/optout.

Harry Lee

unread,
Aug 25, 2016, 7:36:24 PM8/25/16
to chromi...@chromium.org
PhistucK

On Thu, Aug 25, 2016 at 8:30 PM, Harry Lee <harryl...@gmail.com> wrote:
Thanks, I've tried this approach and also something like:
 
var req = new XMLHttpRequest();
if (req.readyState == 4) {
            if (req.status === 200) {
                // handle successful case
            } else {
               // handle failed case
               // console.log("Error loading stuff, status: " + req.statusText);
            }
}

Both can correctly pick up the failed case, but I still cannot log the actual exception text "net::ERR_INSECURE_RESPONSE" or other net::ERR_*

PhistucK

unread,
Aug 26, 2016, 3:17:12 AM8/26/16
to Harry Lee, Chromium Apps
Those are internal network-stack level errors. They are not exposed to the web.
But the cause of this error is something you can easily check ahead of time (if (window.location.protocol === "https:" && url.indexOf("https://") !== 0) or something similar).


PhistucK
Reply all
Reply to author
Forward
0 new messages