Connection timeout - display a connection error page

119 views
Skip to first unread message

jra...@gmail.com

unread,
Sep 26, 2013, 9:51:27 PM9/26/13
to node-...@googlegroups.com

When a user starts my app it displays a webpage. If the web server is down, or the internet connection is lost, the page just displays a blank white background. Is there a way I can have it display a page saying cannot make connection, and to retry, or something similar?

Thanks for any help.

Laszlo Z. Antal

unread,
Sep 27, 2013, 1:43:02 AM9/27/13
to node-...@googlegroups.com, node-...@googlegroups.com
Hi,

On Sep 26, 2013, at 6:51 PM, jra...@gmail.com wrote:

When a user starts my app it displays a webpage. If the web server is down, or the internet connection is lost, the page just displays a blank white background. Is there a way I can have it display a page saying cannot make connection, and to retry, or something similar?

Thanks for any help.


I use node dns module. Here is a quick example replace google with your website address:
"""
var dns = require("dns");
dns.resolve("google.com", function(error){
if(error){ // display your error page }
else{ // load your page }
});
"""
Internet connection can go down anytime so I have that in a timer to check it twice a second so I can display a warning. 

Hope it helps

Laszlo

--
You received this message because you are subscribed to the Google Groups "node-webkit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to node-webkit...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Anthony Ettinger

unread,
Sep 27, 2013, 3:05:54 AM9/27/13
to node-...@googlegroups.com
I set a flag called 'uncaught' because I don't want to show errors in production, but when developing, I DO want to see them:

        if ( uncaught ) {
            process.on('uncaughtException', function(err) {
                c.log("Uncaught exception!", err);
            });
        }
Message has been deleted

Anatoly Pashin

unread,
Sep 27, 2013, 11:29:01 AM9/27/13
to node-...@googlegroups.com
Dns is builtin module of nodejs, so it must work. Here is api docs: http://nodejs.org/api/dns.html

Anyway, the question is still here: we've got no any error pages in node-webkit and I think that's bad.
Checked source and resource for error page is present: https://github.com/rogerwang/chromium/blob/node/chrome/renderer/resources/neterror.html 

Looks like some part of renderer is not activated or just broken. I don't know how to debug/investigate and going to open issue on github.


2013/9/27 <jra...@gmail.com>
I'm still new to node .. is the dns module built in to node-webkit? I tried implementing this into my app, but i wasn't able to get a response. Any suggestions?



--
Пашин Анатолий,
эникейщик.

LZAntal

unread,
Sep 27, 2013, 12:17:58 PM9/27/13
to node-...@googlegroups.com
Hi,

On Sep 27, 2013, at 8:29 AM, Anatoly Pashin <anatoly...@gmail.com> wrote:

Dns is builtin module of nodejs, so it must work. Here is api docs: http://nodejs.org/api/dns.html

Anyway, the question is still here: we've got no any error pages in node-webkit and I think that's bad.
Checked source and resource for error page is present: https://github.com/rogerwang/chromium/blob/node/chrome/renderer/resources/neterror.html 

Looks like some part of renderer is not activated or just broken. I don't know how to debug/investigate and going to open issue on github.


I created a generic error.html page with options on it etc… and use window.location if there is an error. Also I use the url to pass over information to display messages and error codes.


Laszlo

jra...@gmail.com

unread,
Sep 27, 2013, 12:49:07 PM9/27/13
to node-...@googlegroups.com
Would you be able to share an example of how you handle this?

jra...@gmail.com

unread,
Sep 27, 2013, 12:52:04 PM9/27/13
to node-...@googlegroups.com
Thanks for your help

Anatoly Pashin

unread,
Sep 27, 2013, 12:58:16 PM9/27/13
to node-...@googlegroups.com
Messed up with url of neterror.html… it's not used repo, same file is present in https://github.com/zcbenz/chromium/blob/node/chrome/renderer/resources/neterror.html

Looks like error pages is handled using chrome:// internal url scheme with no success. If you navigate chrome://test/ and http://error.page/ network tab of dev tools says you requested data:text/html,chromewebdata. Chrome v30 on my computer doing same requests.

So my opinion is chrome:// url scheme is broken. Maybe that's caused by introducing nw: scheme (there are some core files override).

@LZAntal I know this problem has workarounds and can be resolved. But we need error pages, don't we? Example: in package.json 'main' is set to http://somewhere.remote and is not unreachable. Is white page good for user? Of course not! 


2013/9/28 LZAntal <lza...@gmail.com>



--
Пашин Анатолий,
эникейщик.

LZAntal

unread,
Sep 27, 2013, 1:02:12 PM9/27/13
to node-...@googlegroups.com
Hi,


On Sep 27, 2013, at 9:58 AM, Anatoly Pashin <anatoly...@gmail.com> wrote:

Messed up with url of neterror.html… it's not used repo, same file is present in https://github.com/zcbenz/chromium/blob/node/chrome/renderer/resources/neterror.html

Looks like error pages is handled using chrome:// internal url scheme with no success. If you navigate chrome://test/ and http://error.page/ network tab of dev tools says you requested data:text/html,chromewebdata. Chrome v30 on my computer doing same requests.

So my opinion is chrome:// url scheme is broken. Maybe that's caused by introducing nw: scheme (there are some core files override).

@LZAntal I know this problem has workarounds and can be resolved. But we need error pages, don't we? Example: in package.json 'main' is set to http://somewhere.remote and is not unreachable. Is white page good for user? Of course not! 


Of course we need error pages :) I was merely suggesting a workaround for the time being. I will have more time next week I will dive into the source code to see if it's an easy fix/addition.


Laszlo

LZAntal

unread,
Sep 27, 2013, 1:49:25 PM9/27/13
to node-...@googlegroups.com
Hi,

On Sep 27, 2013, at 9:49 AM, jra...@gmail.com wrote:

Would you be able to share an example of how you handle this?

Sure, actually I will just turn it into a module and upload it to github this weekend. It's simple, it also handles creating an error object from the url and inserting their value into elements on the page. Will keep you posted.


Laszlo

LZAntal

unread,
Sep 27, 2013, 2:11:28 PM9/27/13
to node-...@googlegroups.com
Hi,

On Sep 27, 2013, at 10:49 AM, LZAntal <lza...@gmail.com> wrote:

> Hi,
>
> On Sep 27, 2013, at 9:49 AM, jra...@gmail.com wrote:
>
>> Would you be able to share an example of how you handle this?
>
> Sure, actually I will just turn it into a module and upload it to github this weekend. It's simple, it also handles creating an error object from the url and inserting their value into elements on the page. Will keep you posted.
>

Looking at it more I might not have time to make this happen this weekend and it has a small bug I don't want to deal with.
So here is the page I'm using right now instead of the JS Class(once it's stable I will switch over to it and publish it on github)

Save this into error.html
"""
<!doctype html>
<html lang="us">
<head>
<meta charset="utf-8">
<title>RaptorGL Error Page</title>
</head>
<body>
<h3>Error occured</h3>
<h4>Error code: <span id="errorcode"></span></h4>
<h4>Error message: <span id="errormsg"></span></h4>
<script>
var url = window.location.search;
if(url){
url = url.substring(1);
var urlarr = url.split('&');
var error = {};
urlarr.forEach(function(item, indx){
var kv = item.split('=');
var k = kv[0];
var v = kv[1].split('%20').join(' ');
error[k] = v;
var d = null;
(d = document.getElementById(k))? d.innerHTML = v : console.log('missing elem with id:'+k);
});
}
</script>
</body>
</html>
"""

And call it like this from anywhere in your code. Don't forget to add app:// if you are using it::
window.location = 'error.html?errormsg=Error occured in the app&errorcode=234'

As you can see you can add as many message you want. Make the url key the same as the element id on the error page and it will auto insert the value into it.
Also it adds all the key value pairs to the error object.

jra...@gmail.com

unread,
Sep 29, 2013, 7:47:24 AM9/29/13
to node-...@googlegroups.com, jra...@gmail.com
Thanks for your help guys, I look forward to an update to fix this issue. It would be great to have a way to customize an error page on connection timeout say through the manifest under maybe window, or webkit section.

Bg Sosh

unread,
Sep 4, 2015, 6:28:59 AM9/4/15
to nw.js, node-...@googlegroups.com, jra...@gmail.com
Has there been any progress on this?  Did you open a github issue? (If not I'll do that).

Thanks

pierred...@gmail.com

unread,
Sep 4, 2015, 12:58:27 PM9/4/15
to nw.js, node-...@googlegroups.com, jra...@gmail.com
In my opinion a custom error page for your user would be better than a nw.js default one so that you keep your app's design and look less like a web browser.
The idea to use DNS modules could be interesting, but why not just try to render the page and in case of a timeout display your custom error message?

Bg Sosh

unread,
Sep 4, 2015, 2:14:36 PM9/4/15
to nw.js, node-...@googlegroups.com, jra...@gmail.com
Because if you need to forward to a url (using e.g. location.href = url), and the server server for that url does not respond, then you have no opportunity to handle this in the page that does the forwarding.  Currently nw.js just shows a blank page.  IMO nw.js should at least show an error of some sort, but what would be perfect is being able to specify static pages that nw.js would display in these various error modes.

Perhaps I'm misunderstanding you though.  Could provide an example of how you propose to display a custom error message in this situation?
Reply all
Reply to author
Forward
0 new messages