Files
piratepoet/lib/API/ErrorResponse.php
Jonathan Labreuille 2e88d7cce0 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,...)
2016-08-02 17:08:43 +02:00

34 lines
737 B
PHP

<?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;
}
}