Commit 90d669df authored by Armand Bour's avatar Armand Bour Committed by Mathieu Giraud

js/*.js: Fix error when db is undefined in multiple classes

The scatterplot, builder, graph, and list classes were not checking if
the database reference was defined, causing a JavaScript error when an
exception was thrown in the functions. This could only occur when not
using any database. This commit implements the behaviour seen in
segmenter.js: the exception is thrown if no database reference is defined
so that the exception can be seen in the JavaScript console, using a
function added to tools.js.
parent 016e050e
......@@ -47,7 +47,7 @@ Builder.prototype = {
else this.resizeGraph(50)
} catch (err) {
this.db.error(err.stack)
sendErrorToDb(err, this.db);
}
},
......@@ -57,7 +57,7 @@ Builder.prototype = {
this.build_info_container()
this.updateTagBox();
} catch(err) {
this.db.error(err.stack)
sendErrorToDb(err, this.db);
}
},
......@@ -595,7 +595,11 @@ Builder.prototype = {
this.initTag();
} catch(err) {
this.db.error(err.stack);
if (this.db == undefined) {
throw err;
} else {
this.db.error(err.stack);
}
}
},
......
......@@ -210,7 +210,7 @@ Graph.prototype = {
this.build_menu()
.build_list();
} catch(err) {
this.db.error(err.stack);
sendErrorToDb(err, this.db);
}
return this
......
......@@ -115,7 +115,7 @@ List.prototype = {
document.body.appendChild(this.dataMenu);
} catch(err) {
this.db.error(err.stack);
sendErrorToDb(err, this.db);
}
},
......@@ -129,7 +129,7 @@ List.prototype = {
this.build_data_list()
this.resize();
} catch(err) {
this.db.error(err.stack);
sendErrorToDb(err, this.db);
}
},
......
......@@ -315,7 +315,7 @@ ScatterPlot.prototype = {
this.tsne_ready=false;
} catch(err) {
this.db.error(err.stack);
sendErrorToDb(err, this.db);
}
},
......@@ -1338,7 +1338,7 @@ ScatterPlot.prototype = {
.getTime() - startTime;
//console.log("update sp: " + elapsedTime + "ms");
} catch(err) {
this.db.error(err.stack);
sendErrorToDb(err, this.db);
}
},
......
......@@ -328,11 +328,7 @@ Segment.prototype = {
}
});
} catch(err) {
if (typeof this.db == 'undefined') {
throw err
} else {
this.db.error(err.stack);
}
sendErrorToDb(err, this.db);
}
},
......
......@@ -222,3 +222,17 @@ function nice_floor(x)
return x;
}
}
/**
* Sends error to the specified database reference.
* If database is undefined, throws the specified error.
* @param {Error} err - the error to send
* @param {Database} db - the database reference
*/
function sendErrorToDb(err, db) {
if (db) {
db.error(err.stack);
} else {
throw err;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment