3

I'm writing a Stream Deck plugin in Javascript and I want to log errors to a file. I can't figure out how to capture details of network errors. These errors appear in the debug console, but how can I get them in my own log? The xhr.onerror() method returns not much useful info, just status code 0. I tried adding a window error event listener, but that never triggers. For example this code here:

var xhr = new XMLHttpRequest()
xhr.onerror = function() {console.log('xhr error', arguments)}
window.onerror = function() {console.log('window error', arguments)}
xhr.open('GET', 'http://badurl12345')
xhr.send()

Running this code in the debug console, I see GET http://badurl12345/ net::ERR_NAME_NOT_RESOLVED. But I can't get this info from the error handler.

Elliott B
  • 980
  • 9
  • 32

1 Answers1

0

I don't think that level of information is available to the JavaScript code. Even the much-newer fetch API severely restricts the information you get when a network error occurs (such as your name resolution failure example):

A response whose type is "error" is known as a network error.

A network error is a response whose status is always 0, status message is always the empty byte sequence, header list is always empty, and body is always null.

T.J. Crowder
  • 1,031,962
  • 187
  • 1,923
  • 1,875