Skip to content

Commit b30b1b1

Browse files
committed
Added error messages for fetch/fetch_feedback when something goes wrong
1 parent 649d655 commit b30b1b1

File tree

4 files changed

+114
-8
lines changed

4 files changed

+114
-8
lines changed

nbgrader/nbextensions/assignment_list/assignment_list.js

Lines changed: 56 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,25 @@ define([
381381
return container;
382382
};
383383

384+
Assignment.prototype.fetch_error = function (data) {
385+
var body = $('<div/>').attr('id', 'fetch-message');
386+
387+
body.append(
388+
$('<div/>').append(
389+
$('<p/>').text('Assignment not fetched:')
390+
)
391+
);
392+
body.append(
393+
$('<pre/>').text(data.value)
394+
);
395+
396+
dialog.modal({
397+
title: "Fetch failed",
398+
body: body,
399+
buttons: { OK: { class : "btn-primary" } }
400+
});
401+
};
402+
384403
Assignment.prototype.submit_error = function (data) {
385404
var body = $('<div/>').attr('id', 'submission-message');
386405

@@ -400,6 +419,25 @@ define([
400419
});
401420
};
402421

422+
Assignment.prototype.fetchfeedback_error = function (data) {
423+
var body = $('<div/>').attr('id', 'fetchfeedback-message');
424+
425+
body.append(
426+
$('<div/>').append(
427+
$('<p/>').text('Feedback not fetched:')
428+
)
429+
);
430+
body.append(
431+
$('<pre/>').text(data.value)
432+
);
433+
434+
dialog.modal({
435+
title: "Fetch Feedback failed",
436+
body: body,
437+
buttons: { OK: { class : "btn-primary" } }
438+
});
439+
};
440+
403441
Assignment.prototype.make_button = function () {
404442
var that = this;
405443
var container = $('<span/>').addClass('item_status col-sm-4');
@@ -417,7 +455,15 @@ define([
417455
},
418456
type : "POST",
419457
dataType : "json",
420-
success : $.proxy(that.on_refresh, that),
458+
success : function (data, status, xhr) {
459+
if (!data.success) {
460+
that.fetch_error(data);
461+
button.text('Fetch');
462+
button.removeAttr('disabled');
463+
} else {
464+
that.on_refresh(data, status, xhr);
465+
}
466+
},
421467
error : function (xhr, status, error) {
422468
container.empty().text("Error fetching assignment.");
423469
utils.log_ajax_error(xhr, status, error);
@@ -479,7 +525,15 @@ define([
479525
},
480526
type : "POST",
481527
dataType : "json",
482-
success : $.proxy(that.on_refresh, that),
528+
success : function (data, status, xhr) {
529+
if (!data.success) {
530+
that.fetchfeedback_error(data);
531+
button.text('Fetch Feedback');
532+
button.removeAttr('disabled');
533+
} else {
534+
that.on_refresh(data, status, xhr);
535+
}
536+
},
483537
error : function (xhr, status, error) {
484538
container.empty().text("Error fetching feedback.");
485539
utils.log_ajax_error(xhr, status, error);

nbgrader/server_extensions/assignment_list/handlers.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -313,8 +313,11 @@ def post(self, action):
313313
if action == 'fetch':
314314
assignment_id = data['assignment_id']
315315
course_id = data['course_id']
316-
self.manager.fetch_assignment(course_id, assignment_id)
317-
self.finish(json.dumps(self.manager.list_assignments(course_id=course_id)))
316+
output = self.manager.fetch_assignment(course_id, assignment_id)
317+
if output["success"]:
318+
self.finish(json.dumps(self.manager.list_assignments(course_id=course_id)))
319+
else:
320+
self.finish(json.dumps(output))
318321
elif action == 'submit':
319322
assignment_id = data['assignment_id']
320323
course_id = data['course_id']
@@ -326,8 +329,11 @@ def post(self, action):
326329
elif action == 'fetch_feedback':
327330
assignment_id = data['assignment_id']
328331
course_id = data['course_id']
329-
self.manager.fetch_feedback(course_id, assignment_id)
330-
self.finish(json.dumps(self.manager.list_assignments(course_id=course_id)))
332+
output = self.manager.fetch_feedback(course_id, assignment_id)
333+
if output["success"]:
334+
self.finish(json.dumps(self.manager.list_assignments(course_id=course_id)))
335+
else:
336+
self.finish(json.dumps(output))
331337

332338

333339
class CourseListHandler(BaseAssignmentHandler):

src/assignment_list/assignmentlist.ts

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,21 @@ class Assignment {
247247
return container;
248248
};
249249

250+
private fetch_error(data: { value: any; }): void {
251+
252+
const body_title = React.createElement('p', null, 'Assignment not fetched:');
253+
const body_content = React.createElement('pre', null, data.value);
254+
const body = React.createElement("div", {'id': 'fetch-message'}, [body_title, body_content]);
255+
256+
showNbGraderDialog({
257+
title: "Fetch Failed",
258+
body: body,
259+
buttons: [Dialog.okButton()]
260+
}, true);
261+
262+
263+
};
264+
250265
private submit_error(data: { value: any; }): void {
251266

252267
const body_title = React.createElement('p', null, 'Assignment not submitted:');
@@ -260,6 +275,21 @@ class Assignment {
260275
}, true);
261276

262277

278+
};
279+
280+
private fetchfeedback_error(data: { value: any; }): void {
281+
282+
const body_title = React.createElement('p', null, 'Feedback not fetched:');
283+
const body_content = React.createElement('pre', null, data.value);
284+
const body = React.createElement("div", {'id': 'fetchfeedback-message'}, [body_title, body_content]);
285+
286+
showNbGraderDialog({
287+
title: "Fetch Failed",
288+
body: body,
289+
buttons: [Dialog.okButton()]
290+
}, true);
291+
292+
263293
};
264294

265295
private make_button(): HTMLSpanElement{
@@ -282,7 +312,13 @@ class Assignment {
282312
method: 'POST'
283313
});
284314

285-
that.on_refresh(reply);
315+
if(!reply.success){
316+
that.fetch_error(reply);
317+
button.innerText = 'Fetch'
318+
button.removeAttribute('disabled')
319+
}else{
320+
that.on_refresh(reply);
321+
}
286322
} catch (reason) {
287323
remove_children(container);
288324
container.innerText = 'Error fetching assignment.';
@@ -335,7 +371,13 @@ class Assignment {
335371
method: 'POST'
336372
});
337373

338-
that.on_refresh(reply);
374+
if(!reply.success){
375+
that.fetchfeedback_error(reply);
376+
button.innerText = 'Fetch Feedback'
377+
button.removeAttribute('disabled')
378+
}else{
379+
that.on_refresh(reply);
380+
}
339381

340382
} catch (reason) {
341383
remove_children(container);

style/validation_message.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
1+
#fetch-message p,
12
#submission-message p,
3+
#fetchfeedback-message p,
24
#validation-message p {
35
margin-bottom: 1em;
46
padding-top: 1em;
57
}
68

9+
#fetch-message pre,
710
#submission-message pre,
11+
#fetchfeedback-message pre,
812
#validation-message pre {
913
border: solid var(--jp-border-color2) 1px;
1014
padding: 5px;

0 commit comments

Comments
 (0)