Improve error handling for failed AJAX requests
[MAILPOET-929]
This commit is contained in:
@ -1,3 +1,18 @@
|
|||||||
|
function requestFailed(xhr) {
|
||||||
|
if (xhr.responseJSON) {
|
||||||
|
return xhr.responseJSON;
|
||||||
|
}
|
||||||
|
var message = "An error has happened while performing a request, the server has responded with response code "
|
||||||
|
+ xhr.status;
|
||||||
|
return {
|
||||||
|
errors: [
|
||||||
|
{
|
||||||
|
message: message
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
define('ajax', ['mailpoet', 'jquery', 'underscore'], function(MailPoet, jQuery, _) {
|
define('ajax', ['mailpoet', 'jquery', 'underscore'], function(MailPoet, jQuery, _) {
|
||||||
|
|
||||||
MailPoet.Ajax = {
|
MailPoet.Ajax = {
|
||||||
@ -60,9 +75,7 @@ define('ajax', ['mailpoet', 'jquery', 'underscore'], function(MailPoet, jQuery,
|
|||||||
'json'
|
'json'
|
||||||
).then(function(data) {
|
).then(function(data) {
|
||||||
return data;
|
return data;
|
||||||
}, function(xhr) {
|
}, requestFailed);
|
||||||
return xhr.responseJSON;
|
|
||||||
});
|
|
||||||
|
|
||||||
// clear options
|
// clear options
|
||||||
this.options = {};
|
this.options = {};
|
||||||
|
Reference in New Issue
Block a user