Revert "Improve ajax errors [MAILPOET-929]"

This commit is contained in:
mrcasual
2017-06-22 20:04:10 -04:00
committed by GitHub
parent 3fafe2bd6a
commit 81c3e2facf
2 changed files with 74 additions and 88 deletions

View File

@@ -1,19 +1,5 @@
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: {},
@@ -58,6 +44,7 @@ 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)) {
@@ -67,14 +54,16 @@ define('ajax', ['mailpoet', 'jquery', 'underscore'], function(MailPoet, jQuery,
} }
// ajax request // ajax request
var deferred = jQuery.post( 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;
}, _.partial(requestFailed, MailPoet.I18n.t('ajaxFailedErrorMessage'))); }, function(xhr) {
return xhr.responseJSON;
});
// clear options // clear options
this.options = {}; this.options = {};

View File

@@ -55,9 +55,6 @@ 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 %>