Revert "Revert "Improve ajax errors [MAILPOET-929]""
This reverts commit 81c3e2facf
.
This commit is contained in:
@@ -1,5 +1,19 @@
|
|||||||
|
function requestFailed(errorMessage, xhr) {
|
||||||
|
if (xhr.responseJSON) {
|
||||||
|
return xhr.responseJSON;
|
||||||
|
}
|
||||||
|
var message = errorMessage.replace("%d", xhr.status);
|
||||||
|
return {
|
||||||
|
errors: [
|
||||||
|
{
|
||||||
|
message: message
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
define('ajax', ['mailpoet', 'jquery', 'underscore'], function(MailPoet, jQuery, _) {
|
define('ajax', ['mailpoet', 'jquery', 'underscore'], function(MailPoet, jQuery, _) {
|
||||||
'use strict';
|
|
||||||
MailPoet.Ajax = {
|
MailPoet.Ajax = {
|
||||||
version: 0.5,
|
version: 0.5,
|
||||||
options: {},
|
options: {},
|
||||||
@@ -44,7 +58,6 @@ define('ajax', ['mailpoet', 'jquery', 'underscore'], function(MailPoet, jQuery,
|
|||||||
|
|
||||||
// set request params
|
// set request params
|
||||||
var params = this.getParams();
|
var params = this.getParams();
|
||||||
var deferred = jQuery.Deferred();
|
|
||||||
|
|
||||||
// remove null values from the data object
|
// remove null values from the data object
|
||||||
if (_.isObject(params.data)) {
|
if (_.isObject(params.data)) {
|
||||||
@@ -54,16 +67,14 @@ define('ajax', ['mailpoet', 'jquery', 'underscore'], function(MailPoet, jQuery,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ajax request
|
// ajax request
|
||||||
deferred = jQuery.post(
|
var deferred = jQuery.post(
|
||||||
this.options.url,
|
this.options.url,
|
||||||
params,
|
params,
|
||||||
null,
|
null,
|
||||||
'json'
|
'json'
|
||||||
).then(function(data) {
|
).then(function(data) {
|
||||||
return data;
|
return data;
|
||||||
}, function(xhr) {
|
}, _.partial(requestFailed, MailPoet.I18n.t('ajaxFailedErrorMessage')));
|
||||||
return xhr.responseJSON;
|
|
||||||
});
|
|
||||||
|
|
||||||
// clear options
|
// clear options
|
||||||
this.options = {};
|
this.options = {};
|
||||||
|
@@ -55,6 +55,9 @@ jQuery('.toplevel_page_mailpoet-newsletters.menu-top-last')
|
|||||||
'mailpoet.js'
|
'mailpoet.js'
|
||||||
)%>
|
)%>
|
||||||
|
|
||||||
|
<%= localize({
|
||||||
|
'ajaxFailedErrorMessage': __('An error has happened while performing a request, the server has responded with response code %d'),
|
||||||
|
}) %>
|
||||||
<% block translations %><% endblock %>
|
<% block translations %><% endblock %>
|
||||||
|
|
||||||
<% block after_translations %><% endblock %>
|
<% block after_translations %><% endblock %>
|
||||||
|
Reference in New Issue
Block a user