JavaScript function for getting reasonable error message from an XHR response

This commit is contained in:
Sybren A. Stüvel 2017-12-22 16:25:39 +01:00
parent 766e766f50
commit 46612a9f68

View File

@ -361,6 +361,20 @@ function getNotificationsLoop() {
}, 30000);
}
/* Returns a more-or-less reasonable message given an error response object. */
function xhrErrorResponseMessage(err) {
if (typeof err.responseJSON == 'undefined')
return err.statusText;
if (typeof err.responseJSON._error != 'undefined' && typeof err.responseJSON._error.message != 'undefined')
return err.responseJSON._error.message;
if (typeof err.responseJSON._message != 'undefined')
return err.responseJSON._message
return err.statusText;
}
/* Notifications: Toastr Defaults */
toastr.options.showDuration = 50;
toastr.options.progressBar = true;