diff --git a/lib/API/Endpoints/Mailer.php b/lib/API/Endpoints/Mailer.php index 4ff8f0c158..2b71688c05 100644 --- a/lib/API/Endpoints/Mailer.php +++ b/lib/API/Endpoints/Mailer.php @@ -1,11 +1,12 @@ send($data['newsletter'], $data['subscriber']); } catch(\Exception $e) { - $result = false; - $response['errors'] = array($e->getMessage()); + return $this->errorResponse(array( + $e->getCode() => $e->getMessage() + )); + } + + if($result === false) { + return $this->errorResponse(array( + APIError::BAD_REQUEST => __("The email could not be sent. Please check your settings.") + )); + } else { + return $this->successResponse(null); } - $response['result'] = ($result) ? true : false; - return $response; } } \ No newline at end of file diff --git a/lib/API/Response.php b/lib/API/Response.php index acbc927e2f..96c6aaeff9 100644 --- a/lib/API/Response.php +++ b/lib/API/Response.php @@ -27,7 +27,7 @@ abstract class Response { if(!empty($this->meta)) { $response['meta'] = $this->meta; } - if(!empty($data)) { + if($data !== null) { $response = array_merge($response, $data); } diff --git a/lib/API/SuccessResponse.php b/lib/API/SuccessResponse.php index 35c2134741..d3be62ae00 100644 --- a/lib/API/SuccessResponse.php +++ b/lib/API/SuccessResponse.php @@ -6,12 +6,14 @@ if(!defined('ABSPATH')) exit; class SuccessResponse extends Response { public $data; - function __construct($data = array(), $meta = array(), $status = self::STATUS_OK) { + function __construct($data = null, $meta = null, $status = self::STATUS_OK) { parent::__construct($status, $meta); $this->data = $data; } function getData() { + if($this->data === null) return null; + return array( 'data' => $this->data ); diff --git a/views/settings/mta.html b/views/settings/mta.html index 540dd40a61..e0c2f6092b 100644 --- a/views/settings/mta.html +++ b/views/settings/mta.html @@ -699,36 +699,20 @@ email: recipient } } - }).done(function(response) { + }).always(function() { MailPoet.Modal.loading(false); - if(response.result === true) { - MailPoet.Notice.success( - "<%= __('The email has been sent! Check your inbox.') %>", + }).done(function(response) { + MailPoet.Notice.success( + "<%= __('The email has been sent! Check your inbox.') %>", + { scroll: true } + ); + }).fail(function(response) { + if (response.errors.length > 0) { + MailPoet.Notice.error( + response.errors.map(function(error) { return error.message; }), { scroll: true } ); - } else { - if (response.errors) { - MailPoet.Notice.error( - "<%= __('The email could not be sent: ') %> " + response.errors, - { scroll: true } - ); - } - else { - if(mailer.method === 'PHPMail') { - MailPoet.Notice.error( - "<%= __('The email could not be sent. Please contact your host to fix this issue.') %>", - { scroll: true, static: true } - ); - } else { - MailPoet.Notice.error( - "<%= __('The email could not be sent. Please check your settings.') %>", - { scroll: true } - ); - } - } } - }).error(function(response) { - MailPoet.Modal.loading(false); }); });