From 5acea4c89d57c4a6bb7c2492e1ebdb3766fa3f1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C4=93teris=20Caune?= Date: Wed, 22 Jul 2020 18:36:11 +0300 Subject: [PATCH] Update Node.js pinging examples -- handle the 'error' event. --- templates/docs/javascript.html | 4 +++- templates/docs/javascript.md | 4 +++- templates/front/snippets/node.html | 4 +++- templates/front/snippets/node.txt | 4 +++- 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/templates/docs/javascript.html b/templates/docs/javascript.html index 012b64ae..03a4ae26 100644 --- a/templates/docs/javascript.html +++ b/templates/docs/javascript.html @@ -1,7 +1,9 @@

Javascript

Below is an example of making a HTTP request to SITE_NAME from Node.js.

var https = require('https');
-https.get("PING_URL");
+https.get('PING_URL').on('error', (err) => {
+    console.log('Ping failed: ' + err)
+});
 
diff --git a/templates/docs/javascript.md b/templates/docs/javascript.md index 28881533..d30dfedc 100644 --- a/templates/docs/javascript.md +++ b/templates/docs/javascript.md @@ -4,7 +4,9 @@ Below is an example of making a HTTP request to SITE_NAME from Node.js. ```js var https = require('https'); -https.get("PING_URL"); +https.get('PING_URL').on('error', (err) => { + console.log('Ping failed: ' + err) +}); ``` You can also send pings from a browser environment. SITE_NAME sets the diff --git a/templates/front/snippets/node.html b/templates/front/snippets/node.html index fa2eb4d7..76b6b8ec 100644 --- a/templates/front/snippets/node.html +++ b/templates/front/snippets/node.html @@ -1,3 +1,5 @@
var https = require('https');
-https.get("{{ ping_url }}");
+https.get('{{ ping_url }}').on('error', (err) => {
+    console.log('Ping failed: ' + err)
+});
 
diff --git a/templates/front/snippets/node.txt b/templates/front/snippets/node.txt index 5728ac5b..7398a390 100644 --- a/templates/front/snippets/node.txt +++ b/templates/front/snippets/node.txt @@ -1,2 +1,4 @@ var https = require('https'); -https.get("PING_URL"); +https.get('PING_URL').on('error', (err) => { + console.log('Ping failed: ' + err) +}); \ No newline at end of file