Skip to content
Snippets Groups Projects
Commit cc5764b0 authored by Shirlei Chaves's avatar Shirlei Chaves
Browse files

Catch non json results when verifying election

If you try to verify a election and you aren't allowed, you get the following
error. This is because it is expected a JSON result and you get, for instance,
a html page to login.

VM65:1 Uncaught SyntaxError: Unexpected token < in JSON at position 0
    at JSON.parse (<anonymous>)
    at Function.HELIOS.Election.fromJSONString (helios.js:127)
    at Object.success (verify.html?election_url=/helios/elections/258ca6b1-afa4-49a3-b484-c31679d2ebbe:100)
    at success (jquery-1.2.2.min.js:28)
    at onreadystatechange (jquery-1.2.2.min.js:27)
parent 0b7da7a9
No related branches found
No related tags found
No related merge requests found
...@@ -97,6 +97,7 @@ function load_election_and_ballots(election_url) { ...@@ -97,6 +97,7 @@ function load_election_and_ballots(election_url) {
// the hash will be computed within the setup function call now // the hash will be computed within the setup function call now
$.get(election_url, function(raw_json) { $.get(election_url, function(raw_json) {
try {
election = HELIOS.Election.fromJSONString(raw_json); election = HELIOS.Election.fromJSONString(raw_json);
result_append("loaded election: " + election.name); result_append("loaded election: " + election.name);
result_append("election fingerprint: " + election.get_hash()); result_append("election fingerprint: " + election.get_hash());
...@@ -242,6 +243,12 @@ function load_election_and_ballots(election_url) { ...@@ -242,6 +243,12 @@ function load_election_and_ballots(election_url) {
}); });
}); });
} catch (error) {
result_append("<p>It appears that you are trying to verify a private election.</p>");
result_append('<p>You can log in as a valid voter or log in as the election admin.</p>');
result_append('<a class="btn" href="' + election_url + '">Log in as a valid voter </a>');
result_append('<a class="btn" href="/auth/?return_url=/verifier/verify.html?election_url=' + election_url + '">Log in as the election admin</a>');
}
}); });
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment