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.
|
// show some message according to the response.
|
||||||
// For eg. A message box showing that the status has been changed
|
// For eg. A message box showing that the status has been changed
|
||||||
})
|
})
|
||||||
.fail(function (data) {
|
.fail(function (jqXHR) {
|
||||||
console.log(data)
|
console.log(jqXHR)
|
||||||
toastr.error(`Failed to change state<br/>${data.responseJSON.status}`);
|
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 () {
|
.always(function () {
|
||||||
console.log('[Done]');
|
console.log('[Done]');
|
||||||
|
|||||||
Reference in New Issue
Block a user