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:
Jonathan Labreuille
2016-08-03 16:04:45 +02:00
parent c5b376bd21
commit 1c6fca7f83
4 changed files with 18 additions and 13 deletions

View File

@ -37,7 +37,9 @@ class API {
function setupAdmin() {
if($this->checkToken() === false) {
(new ErrorResponse(
array('unauthorized' => __('This request is not authorized.')),
array(
Error::UNAUTHORIZED => __('You need to specify a valid API token.')
),
array(),
Response::STATUS_UNAUTHORIZED
))->send();
@ -45,7 +47,9 @@ class API {
if($this->checkPermissions() === false) {
(new ErrorResponse(
array('forbidden' => __('You do not have the required permissions.')),
array(
Error::FORBIDDEN => __('You do not have the required permissions.')
),
array(),
Response::STATUS_FORBIDDEN
))->send();
@ -56,10 +60,13 @@ class API {
function setupPublic() {
if($this->checkToken() === false) {
$response = new ErrorResponse(array(
'unauthorized' => __('This request is not authorized.')
), Response::STATUS_UNAUTHORIZED);
$response->send();
(new ErrorResponse(
array(
Error::UNAUTHORIZED => __('You need to specify a valid API token.')
),
array(),
Response::STATUS_UNAUTHORIZED
))->send();
}
$this->processRoute();
@ -101,7 +108,9 @@ class API {
wp_send_json($response);
}
} catch(\Exception $e) {
(new ErrorResponse(array($e->getMessage())))->send();
(new ErrorResponse(
array($e->getCode() => $e->getMessage())
))->send();
}
}