Skip to content

Commit

Permalink
Fix handling 500s on unlock API (#429)
Browse files Browse the repository at this point in the history
This provides us with better, more informative error messages
in some weird edge cases (notably, 5xx server failure)
  • Loading branch information
dennisjbell authored and jhunt committed Jul 13, 2018
1 parent 7986b63 commit 434cee2
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
1 change: 1 addition & 0 deletions web2/htdocs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -656,6 +656,7 @@ <h2>This SHIELD Core is LOCKED</h2>
<div class="ctl" data-field="unlock-master">
<label for="masterpass">Enter your SHIELD Master Password</label>
<div class="errors">
<span class="error"></span>
<span data-error="missing">Please supply your password.</span>
<span data-error="incorrect">Incorrect password, please try again.</span>
</div>
Expand Down
12 changes: 8 additions & 4 deletions web2/htdocs/shield.js
Original file line number Diff line number Diff line change
Expand Up @@ -1326,6 +1326,7 @@ function divert(page) { // {{{
return page;
}
// }}}
// vim:et:sts=2:ts=2:sw=2

function dispatch(page) {
var argv = page.split(/[:+]/);
Expand Down Expand Up @@ -3339,9 +3340,12 @@ function dispatch(page) {
.on('submit', 'form', function (event) {
event.preventDefault();

var data = $(event.target).serializeObject();
var $form = $(event.target);
$form.reset()
var data = $form.serializeObject();
if (data.master == "") {
$(event.target).error('unlock-master', 'missing');
$form.error('unlock-master', 'missing');
return;
}

api({
Expand All @@ -3355,10 +3359,10 @@ function dispatch(page) {
},
statusCode: {
403: function () {
$(event.target).error('unlock-master', 'incorrect')
$form.error('unlock-master', 'incorrect')
},
500: function (xhr) {
$(event.target).error(xhr.responseJSON);
$form.error(xhr.responseJSON);
}
},
error: {}
Expand Down
12 changes: 8 additions & 4 deletions web2/src/js/shield.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ function divert(page) { // {{{
return page;
}
// }}}
// vim:et:sts=2:ts=2:sw=2

function dispatch(page) {
var argv = page.split(/[:+]/);
Expand Down Expand Up @@ -2042,9 +2043,12 @@ function dispatch(page) {
.on('submit', 'form', function (event) {
event.preventDefault();

var data = $(event.target).serializeObject();
var $form = $(event.target);
$form.reset()
var data = $form.serializeObject();
if (data.master == "") {
$(event.target).error('unlock-master', 'missing');
$form.error('unlock-master', 'missing');
return;
}

api({
Expand All @@ -2058,10 +2062,10 @@ function dispatch(page) {
},
statusCode: {
403: function () {
$(event.target).error('unlock-master', 'incorrect')
$form.error('unlock-master', 'incorrect')
},
500: function (xhr) {
$(event.target).error(xhr.responseJSON);
$form.error(xhr.responseJSON);
}
},
error: {}
Expand Down

0 comments on commit 434cee2

Please sign in to comment.