Improve error handling in state change failure response for better user feedback
This commit is contained in:
@@ -22,9 +22,22 @@
|
||||
// show some message according to the response.
|
||||
// For eg. A message box showing that the status has been changed
|
||||
})
|
||||
.fail(function (data) {
|
||||
console.log(data)
|
||||
toastr.error(`Failed to change state<br/>${data.responseJSON.status}`);
|
||||
.fail(function (jqXHR) {
|
||||
console.log(jqXHR)
|
||||
var msg = 'Unknown error';
|
||||
try {
|
||||
if (jqXHR && jqXHR.responseJSON && jqXHR.responseJSON.status) {
|
||||
msg = jqXHR.responseJSON.status;
|
||||
} else if (jqXHR && jqXHR.responseText) {
|
||||
// fallback to raw responseText (may be HTML)
|
||||
msg = jqXHR.responseText;
|
||||
} else if (jqXHR && jqXHR.statusText) {
|
||||
msg = jqXHR.statusText;
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('Error parsing failure response', e);
|
||||
}
|
||||
toastr.error(`Failed to change state<br/>${msg}`);
|
||||
})
|
||||
.always(function () {
|
||||
console.log('[Done]');
|
||||
|
||||
Reference in New Issue
Block a user