Skip to content

Commit

Permalink
MAINT: show responseText when applicable in alerts
Browse files Browse the repository at this point in the history
This necessitated some messing around with each of the three
onRejected functions I added in 77cb5a6 in order to figure out which
arguments were passed where.

ERROR FUNCTIONS 1 AND 2

For the most part, any error functions that fail due to requests (i.e.
the error functions I just created in autocomplete_search_samples() and
in get_active_samples()) are passed a jqXHR, etc. as arguments -- so we
can just show the responseText.

(These error functions, if ever called,
should be called with a jqXHR since all they're really doing is waiting
on a series of requests to finish. I *guess* it's conceivably possible
they could fail not due to a request if jQuery's code somehow explodes,
but I doubt it.)

ERROR FUNCTION 3

The callback on the promise returned by get_active_samples() -- that
is, the error function declared in modifyWell() -- just receives a
normal rejectionReason as a string if there's an error in the success
function within get_active_samples(), which makes sense since if any
of the requests would fail in get_active_samples() then that would
trigger get_active_samples()' declared error function (with a jqXHR,
etc.  as arguments since a request caused the failure) instead of the
error function on the promise returned by get_active_samples().

TLDR

Phew! That was a lot of long paragraphs. The gist of things here is:
I tested each of the 3 new error callbacks locally, saw what the
responses I was getting were, and adjusted the bootstrapAlert() calls
accordingly to be more informative.
From manual testing and thinking things through these adjustments
should be correct, but even if they aren't (and, say,
error function 1 gets passed a string instead of a jqXHR and things)
then the outcome is the same: an error pops up with some sort of
message. (The difference in that case will be we'll see something like
"[Nice error message:] undefined" instead of
"[Nice error message:] [further information]", which isn't too
horrifying.)
  • Loading branch information
fedarko committed Sep 6, 2019
1 parent 77cb5a6 commit ed55343
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions labcontrol/gui/static/js/plateViewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ PlateViewer.prototype.modifyWell = function(row, col, content) {
},
function(rejectionReason) {
bootstrapAlert(
"Attempting to get a list of sample IDs failed:" + rejectionReason,
"Attempting to get a list of sample IDs failed: " + rejectionReason,
"danger"
);
}
Expand Down Expand Up @@ -820,11 +820,15 @@ function autocomplete_search_samples(request, response) {
});
response(results);
},
function(rejectionReason) {
// If any of the requests fail, the arguments to this "rejection"
// function match the arguments to the corresponding request's
// "error" function: see https://api.jquery.com/jquery.when/, towards the
// bottom of the page. (So we can just show the user jqXHR.responseText.)
function(jqXHR, textStatus, errorThrown) {
bootstrapAlert(
"Attempting to get sample IDs while filling up the autocomplete " +
"dropdown menu failed: " +
rejectionReason,
jqXHR.responseText,
"danger"
);
}
Expand Down Expand Up @@ -911,9 +915,10 @@ function get_active_samples() {
var arg = requests.length === 1 ? [arguments] : arguments;
return merge_sample_responses(arg);
},
function(rejectionReason) {
function(jqXHR, textStatus, errorThrown) {
bootstrapAlert(
"Attempting to get a list of sample IDs failed:" + rejectionReason,
"Attempting to get a list of sample IDs failed: " +
jqXHR.responseText,
"danger"
);
}
Expand Down

0 comments on commit ed55343

Please sign in to comment.