1

I'm using Offline.js library to notify users when they lost internet connectivity. Currently this library intercepts every AJAX request and decides if user have a connection.

Here's a function which is automatically called when connectivity is lost:

Offline.on('down', function () {
    alert('A network error has occurred.');
});

I was wondering if there is any chance to notify users with the actual error message which is logged to console, e.g. net::ERR_CONNECTION_REFUSED or net::ERR_INTERNET_DISCONNECTED?

Thunderforge
  • 19,637
  • 18
  • 83
  • 130
  • You will get those messages in the AJAX request error callback. – A1rPun Apr 29 '14 at 13:41
  • I know, but in this case I need to get those messages in this function particularly (actually I'm doing some more complex things, than alerting the users). – user3232395 Apr 29 '14 at 13:50
  • `Offline` does not send any parameters to the events so it is impossible with this library. Your last resort will be `window.onerror`, save the error in a variable anywhere and use it in your function. – A1rPun Apr 29 '14 at 14:09
  • Thank you for your response. For now I'm suspending my idea, to get those error messages in this function until management says that is essential. – user3232395 Apr 30 '14 at 09:49
  • You could also fork offline.js and add a parameter to the down callback, that should not be too difficult. Maybe somebody even already did it. – PJP Jun 16 '14 at 09:47

1 Answers1

0

That should return the error

 Offline.on('down', function (error) {
    alert('A network error has occurred.' + ' ' + error);
});
batanasov
  • 219
  • 1
  • 2
  • 13