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

var xhr = new XMLHttpRequest(); var xhr = new XMLHttpRequest();


xhr.addEventListener("load", function() { 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) { if (obj.error) {
cb(obj.error); cb(obj.error);
} }


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


// Retry on error // Retry on error
if (err) { if (err) {
console.log(err);
setTimeout(function() { init() }, 2000); setTimeout(function() { init() }, 2000);
return; return;
} }
} }


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


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

+ 1
- 1
package.json View File

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

Loading…
Cancel
Save