Improve error handling in state change failure response for better user feedback

This commit is contained in:
Ross
2025-12-29 12:15:06 +00:00
parent 3e1cb4b54f
commit 465f819973
+16 -3
View File
@@ -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]');