Browse Source

improved error handling

master
mortie 8 years ago
parent
commit
8d0196bf58
2 changed files with 12 additions and 2 deletions
  1. 11
    1
      client.js
  2. 1
    1
      package.json

+ 11
- 1
client.js View File

@@ -3,7 +3,12 @@
var xhr = new XMLHttpRequest();

xhr.addEventListener("load", function() {
var obj = JSON.parse(xhr.responseText);
try {
var obj = JSON.parse(xhr.responseText);
} catch (err) {
console.log(xhr.responseText);
cb(err);
}

if (obj.error) {
cb(obj.error);
@@ -36,10 +41,13 @@
}

function init() {
console.log("init...");
post("/webevents/register", function(err, res) {
console.log("Init done", err ? "with errors" : "no errors");

// Retry on error
if (err) {
console.log(err);
setTimeout(function() { init() }, 2000);
return;
}
@@ -50,7 +58,9 @@
}

function await() {
console.log("await...");
post("/webevents/await/"+key, function(err, res) {
console.log("Await done", err ? "with errors" : "no errors");

// Retry on error
if (err === "ENOTREGISTERED") {

+ 1
- 1
package.json View File

@@ -1,6 +1,6 @@
{
"name": "webevents",
"version": "1.0.1",
"version": "1.0.2",
"description": "A simple library for sending events from the server to the client.",
"main": "index.js",
"scripts": {

Loading…
Cancel
Save