With V2 we should ensure that the status codes are kept in sync

This commit is contained in:
Thomas Müller 2015-08-06 00:01:56 +02:00
parent 55dc74bba4
commit 1d219cf799
3 changed files with 9 additions and 7 deletions

View file

@ -354,15 +354,18 @@ class OC_API {
header($name . ': ' . $value);
}
$meta = $result->getMeta();
$data = $result->getData();
if (self::isV2()) {
$statusCode = self::mapStatusCodes($result->getStatusCode());
if (!is_null($statusCode)) {
$meta['statuscode'] = $statusCode;
OC_Response::setStatus($statusCode);
}
}
self::setContentType($format);
$body = self::renderResult($result, $format);
$body = self::renderResult($format, $meta, $data);
echo $body;
}
@ -452,15 +455,14 @@ class OC_API {
}
/**
* @param OC_OCS_Result $result
* @param string $format
* @return string
*/
public static function renderResult($result, $format) {
public static function renderResult($format, $meta, $data) {
$response = array(
'ocs' => array(
'meta' => $result->getMeta(),
'data' => $result->getData(),
'meta' => $meta,
'data' => $data,
),
);
if ($format == 'json') {

View file

@ -93,7 +93,7 @@ class OC_OCS_Result{
*/
public function getMeta() {
$meta = array();
$meta['status'] = ($this->statusCode === 100) ? 'ok' : 'failure';
$meta['status'] = $this->succeeded() ? 'ok' : 'failure';
$meta['statuscode'] = $this->statusCode;
$meta['message'] = $this->message;
if(isset($this->items)) {

View file

@ -85,7 +85,7 @@ class OCSResponse extends Response {
$r->setTotalItems($this->itemscount);
$r->setItemsPerPage($this->itemsperpage);
return \OC_API::renderResult($r, $this->format);
return \OC_API::renderResult($this->format, $r->getMeta(), $r->getData());
}