Added API/Endpoint abstract class
- (re)Added Endpoints folder to both API and Router - fixed syntax in namespaces - xhr.responseJSON is returned to the fail() - fixed Router endpoints (view in browser, cron,...)
This commit is contained in:
34
lib/API/ErrorResponse.php
Normal file
34
lib/API/ErrorResponse.php
Normal file
@ -0,0 +1,34 @@
|
||||
<?php
|
||||
namespace MailPoet\API;
|
||||
|
||||
if(!defined('ABSPATH')) exit;
|
||||
|
||||
class ErrorResponse extends Response {
|
||||
public $errors;
|
||||
|
||||
function __construct($errors = array(), $meta = array(), $status = self::STATUS_NOT_FOUND) {
|
||||
parent::__construct($status, $meta);
|
||||
$this->errors = $this->formatErrors($errors);
|
||||
}
|
||||
|
||||
function getData() {
|
||||
if(empty($this->errors)) {
|
||||
return false;
|
||||
} else {
|
||||
return array(
|
||||
'errors' => $this->errors
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
function formatErrors($errors = array()) {
|
||||
$formatted_errors = array();
|
||||
foreach($errors as $error => $message) {
|
||||
$formatted_errors[] = array(
|
||||
'error' => $error,
|
||||
'message' => $message
|
||||
);
|
||||
}
|
||||
return $formatted_errors;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user