Skip to content
Snippets Groups Projects
Commit d3062622 authored by Shane Tomlinson's avatar Shane Tomlinson
Browse files

Adding a catch all case when path specific code is started.

* The catch all will print a console log message if console.log is available.
* Adding helpers.log which prints to the console if console.log is available.
parent 237d1ff3
No related branches found
No related tags found
No related merge requests found
......@@ -11,6 +11,7 @@ $(function() {
*/
var bid = BrowserID,
helpers = bid.Helpers,
pageHelpers = bid.PageHelpers,
user = bid.User,
dom = bid.DOM,
......@@ -79,6 +80,11 @@ $(function() {
else if(token && path === "/verify_email_address") {
bid.verifyEmailAddress(token);
}
else {
// Instead of throwing a hard error here, adding a message to the console
// to let developers know something is up.
helpers.log("unknown path");
}
user.checkAuthentication(function(authenticated) {
if (authenticated) {
......
......@@ -67,6 +67,15 @@
}
}
function log(msg) {
try {
window.console.log(msg);
} catch(e) {
// Catch all if console is not available or if it for some reason blows
// up. Do nothing.
}
}
extend(helpers, {
/**
* Extend an object with the properties of another object. Overwrites
......@@ -116,7 +125,14 @@
* parameter is a function.
* @param {variant} [params] - parameters to pass to callback.
*/
complete: complete
complete: complete,
/**
* If the console is available, log a message to it.
* @method log
* @param {string} msg
*/
log: log
});
......
......@@ -103,4 +103,65 @@
equal(url, "https://browserid.org?email=testuser%40testuser.com&status=complete", "correct URL with GET parameters");
});
test("simulate log on browser without console - no exception thrown", function() {
var err,
nativeConsole = window.console;
// Simulate browser without window.console.
window.console = undefined;
try {
helpers.log("test message");
}
catch(e) {
err = e;
}
equal(typeof err, "undefined", "no exception thrown");
window.console = nativeConsole;
});
test("simulate log on browser without console.log - no exception thrown", function() {
var err,
nativeConsole = window.console;
// Simulate browser with console, but without console.log.
window.console = {};
try {
helpers.log("test message");
}
catch(e) {
err = e;
}
equal(typeof err, "undefined", "no exception thrown");
window.console = nativeConsole;
});
test("simulate log on browser with console.log - prints message", function() {
var err,
loggedMessage,
nativeConsole = window.console;
// Simulate browser with console and console.log
window.console = {
log: function(msg) {
loggedMessage = msg;
}
};
try {
helpers.log("test message");
}
catch(e) {
err = e;
}
equal(typeof err, "undefined", "no exception thrown");
equal(loggedMessage, "test message", "correct message logged");
window.console = nativeConsole;
});
}());
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment