diff --git a/assets/js/src/ajax.js b/assets/js/src/ajax.js index 3878a3582a..c44a1bf10b 100644 --- a/assets/js/src/ajax.js +++ b/assets/js/src/ajax.js @@ -60,7 +60,13 @@ define('ajax', ['mailpoet', 'jquery', 'underscore'], function(MailPoet, jQuery, ).then(function(data) { return data; }, function(xhr) { - return xhr.responseJSON; + if (!xhr.responseJSON) { + return { + errors: [{ error: 'undefined', message: "An unknown error occurred." }] + }; + } else { + return xhr.responseJSON; + } }); // clear options diff --git a/lib/API/Endpoints/Settings.php b/lib/API/Endpoints/Settings.php index ec3228ac34..dcf664e93e 100644 --- a/lib/API/Endpoints/Settings.php +++ b/lib/API/Endpoints/Settings.php @@ -21,7 +21,7 @@ class Settings extends APIEndpoint { foreach($settings as $name => $value) { Setting::setValue($name, $value); } - return $this->successResponse(Setting::getAll()); + return $this->successResponse(); } } } diff --git a/lib/API/Endpoints/Setup.php b/lib/API/Endpoints/Setup.php index b7a4929f77..90651784c0 100644 --- a/lib/API/Endpoints/Setup.php +++ b/lib/API/Endpoints/Setup.php @@ -1,10 +1,11 @@ deactivate(); $activator->activate(); - $result = true; + return $this->successResponse(); } catch(\Exception $e) { - $result = false; + return $this->errorResponse(array( + $e->getMessage() + )); } - return array( - 'result' => $result - ); } } diff --git a/tests/unit/API/SetupTest.php b/tests/unit/API/SetupTest.php index fe44d2f3d8..9b45ca14c3 100644 --- a/tests/unit/API/SetupTest.php +++ b/tests/unit/API/SetupTest.php @@ -1,4 +1,5 @@ reset(); - expect($response['result'])->true(); + expect($response->status)->equals(Response::STATUS_OK); $signup_confirmation = Setting::getValue('signup_confirmation.enabled'); - expect($signup_confirmation)->true();*/ + expect($signup_confirmation)->true(); } function _after() { diff --git a/views/settings.html b/views/settings.html index 09b8bc0ddf..0f248f1003 100644 --- a/views/settings.html +++ b/views/settings.html @@ -77,20 +77,20 @@ endpoint: 'settings', action: 'set', data: settings_data + }).always(function() { + MailPoet.Modal.loading(false); }).done(function(response) { MailPoet.Notice.success( "<%= __('Settings saved') %>", { scroll: true } ); - MailPoet.Modal.loading(false); }).fail(function(response) { - if (response.errors !== undefined) { + if (response.errors.length > 0) { MailPoet.Notice.error( response.errors.map(function(error) { return error.message; }), { scroll: true } ); } - MailPoet.Modal.loading(false); }); } diff --git a/views/settings/advanced.html b/views/settings/advanced.html index 29a37f27f4..6e1e555f11 100644 --- a/views/settings/advanced.html +++ b/views/settings/advanced.html @@ -175,13 +175,16 @@ MailPoet.Ajax.post({ 'endpoint': 'setup', 'action': 'reset' + }).always(function() { + MailPoet.Modal.loading(false); }).done(function(response) { - if(response.result === true) { - window.location = "<%= admin_url('admin.php?page=mailpoet-newsletters') %>"; - } else { + window.location = "<%= admin_url('admin.php?page=mailpoet-newsletters') %>"; + }).fail(function(response) { + if (response.errors.length > 0) { MailPoet.Notice.error( - "<%= __('MailPoet could not be reinstalled. You may need to remove it manually first.') %>", - { scroll: true }); + response.errors.map(function(error) { return error.message; }), + { scroll: true } + ); } }); }