fixed ErrorResponse call in API::setupPublic()
- removed empty constructors in updated endpoints - added missing keys to Error class (unauthorized, forbidden)
This commit is contained in:
@ -37,7 +37,9 @@ class API {
|
|||||||
function setupAdmin() {
|
function setupAdmin() {
|
||||||
if($this->checkToken() === false) {
|
if($this->checkToken() === false) {
|
||||||
(new ErrorResponse(
|
(new ErrorResponse(
|
||||||
array('unauthorized' => __('This request is not authorized.')),
|
array(
|
||||||
|
Error::UNAUTHORIZED => __('You need to specify a valid API token.')
|
||||||
|
),
|
||||||
array(),
|
array(),
|
||||||
Response::STATUS_UNAUTHORIZED
|
Response::STATUS_UNAUTHORIZED
|
||||||
))->send();
|
))->send();
|
||||||
@ -45,7 +47,9 @@ class API {
|
|||||||
|
|
||||||
if($this->checkPermissions() === false) {
|
if($this->checkPermissions() === false) {
|
||||||
(new ErrorResponse(
|
(new ErrorResponse(
|
||||||
array('forbidden' => __('You do not have the required permissions.')),
|
array(
|
||||||
|
Error::FORBIDDEN => __('You do not have the required permissions.')
|
||||||
|
),
|
||||||
array(),
|
array(),
|
||||||
Response::STATUS_FORBIDDEN
|
Response::STATUS_FORBIDDEN
|
||||||
))->send();
|
))->send();
|
||||||
@ -56,10 +60,13 @@ class API {
|
|||||||
|
|
||||||
function setupPublic() {
|
function setupPublic() {
|
||||||
if($this->checkToken() === false) {
|
if($this->checkToken() === false) {
|
||||||
$response = new ErrorResponse(array(
|
(new ErrorResponse(
|
||||||
'unauthorized' => __('This request is not authorized.')
|
array(
|
||||||
), Response::STATUS_UNAUTHORIZED);
|
Error::UNAUTHORIZED => __('You need to specify a valid API token.')
|
||||||
$response->send();
|
),
|
||||||
|
array(),
|
||||||
|
Response::STATUS_UNAUTHORIZED
|
||||||
|
))->send();
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->processRoute();
|
$this->processRoute();
|
||||||
@ -101,7 +108,9 @@ class API {
|
|||||||
wp_send_json($response);
|
wp_send_json($response);
|
||||||
}
|
}
|
||||||
} catch(\Exception $e) {
|
} catch(\Exception $e) {
|
||||||
(new ErrorResponse(array($e->getMessage())))->send();
|
(new ErrorResponse(
|
||||||
|
array($e->getCode() => $e->getMessage())
|
||||||
|
))->send();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,9 +7,6 @@ use \MailPoet\Models\Setting;
|
|||||||
if(!defined('ABSPATH')) exit;
|
if(!defined('ABSPATH')) exit;
|
||||||
|
|
||||||
class Settings extends APIEndpoint {
|
class Settings extends APIEndpoint {
|
||||||
function __construct() {
|
|
||||||
}
|
|
||||||
|
|
||||||
function get() {
|
function get() {
|
||||||
return $this->successResponse(Setting::getAll());
|
return $this->successResponse(Setting::getAll());
|
||||||
}
|
}
|
||||||
|
@ -6,9 +6,6 @@ use \MailPoet\Config\Activator;
|
|||||||
if(!defined('ABSPATH')) exit;
|
if(!defined('ABSPATH')) exit;
|
||||||
|
|
||||||
class Setup extends APIEndpoint {
|
class Setup extends APIEndpoint {
|
||||||
function __construct() {
|
|
||||||
}
|
|
||||||
|
|
||||||
function reset() {
|
function reset() {
|
||||||
try {
|
try {
|
||||||
$activator = new Activator();
|
$activator = new Activator();
|
||||||
|
@ -6,6 +6,8 @@ if(!defined('ABSPATH')) exit;
|
|||||||
final class Error {
|
final class Error {
|
||||||
const UNKNOWN = 'unknown';
|
const UNKNOWN = 'unknown';
|
||||||
const BAD_REQUEST = 'bad_request';
|
const BAD_REQUEST = 'bad_request';
|
||||||
|
const UNAUTHORIZED = 'unauthorized';
|
||||||
|
const FORBIDDEN = 'forbidden';
|
||||||
|
|
||||||
private function __construct() {
|
private function __construct() {
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user