diff options
author | Bjoern Schiessle <schiessle@owncloud.com> | 2014-01-13 12:27:05 +0100 |
---|---|---|
committer | Bjoern Schiessle <schiessle@owncloud.com> | 2014-01-13 12:27:05 +0100 |
commit | 68458604703eab0283dc9e4c2c8b3dd1f97aaaef (patch) | |
tree | 1cd53eca60ea6797db5a1e4c615dc7dc2d8b0a7f /lib/private | |
parent | 85e00ad35a63d2d728140f3ece685d79d7a6140c (diff) | |
download | nextcloud-server-68458604703eab0283dc9e4c2c8b3dd1f97aaaef.tar.gz nextcloud-server-68458604703eab0283dc9e4c2c8b3dd1f97aaaef.zip |
keep response message
Diffstat (limited to 'lib/private')
-rw-r--r-- | lib/private/api.php | 42 |
1 files changed, 22 insertions, 20 deletions
diff --git a/lib/private/api.php b/lib/private/api.php index 03d7b7382a5..c713368125c 100644 --- a/lib/private/api.php +++ b/lib/private/api.php @@ -33,7 +33,7 @@ class OC_API { const USER_AUTH = 1; const SUBADMIN_AUTH = 2; const ADMIN_AUTH = 3; - + /** * API Response Codes */ @@ -41,13 +41,13 @@ class OC_API { const RESPOND_SERVER_ERROR = 996; const RESPOND_NOT_FOUND = 998; const RESPOND_UNKNOWN_ERROR = 999; - + /** * api actions */ protected static $actions = array(); private static $logoutRequired = false; - + /** * registers an api call * @param string $method the http method @@ -58,7 +58,7 @@ class OC_API { * @param array $defaults * @param array $requirements */ - public static function register($method, $url, $action, $app, + public static function register($method, $url, $action, $app, $authLevel = OC_API::USER_AUTH, $defaults = array(), $requirements = array()) { @@ -75,7 +75,7 @@ class OC_API { } self::$actions[$name][] = array('app' => $app, 'action' => $action, 'authlevel' => $authLevel); } - + /** * handles an api call * @param array $parameters @@ -125,7 +125,7 @@ class OC_API { self::respond($response, $format); } - + /** * merge the returned result objects into one response * @param array $responses @@ -166,32 +166,31 @@ class OC_API { // Maybe any that are not OC_API::RESPOND_SERVER_ERROR // Merge failed responses if more than one $data = array(); - $meta = array(); foreach($shipped['failed'] as $failure) { $data = array_merge_recursive($data, $failure['response']->getData()); } $picked = reset($shipped['failed']); $code = $picked['response']->getStatusCode(); - $response = new OC_OCS_Result($data, $code); + $meta = $picked['response']->getMeta(); + $response = new OC_OCS_Result($data, $code, $meta['message']); return $response; } elseif(!empty($shipped['succeeded'])) { $responses = array_merge($shipped['succeeded'], $thirdparty['succeeded']); } elseif(!empty($thirdparty['failed'])) { // Merge failed responses if more than one $data = array(); - $meta = array(); foreach($thirdparty['failed'] as $failure) { $data = array_merge_recursive($data, $failure['response']->getData()); } $picked = reset($thirdparty['failed']); $code = $picked['response']->getStatusCode(); - $response = new OC_OCS_Result($data, $code); + $meta = $picked['response']->getMeta(); + $response = new OC_OCS_Result($data, $code, $meta['message']); return $response; } else { $responses = $thirdparty['succeeded']; } // Merge the successful responses - $meta = array(); $data = array(); foreach($responses as $app => $response) { @@ -200,22 +199,25 @@ class OC_API { } else { $data = array_merge_recursive($data, $response['response']->getData()); } - $codes[] = $response['response']->getStatusCode(); + $codes[] = array('code' => $response['response']->getStatusCode(), + 'meta' => $response['response']->getMeta()); } // Use any non 100 status codes $statusCode = 100; + $statusMessage = null; foreach($codes as $code) { - if($code != 100) { - $statusCode = $code; + if($code['code'] != 100) { + $statusCode = $code['code']; + $statusMessage = $code['meta']['message']; break; } } - $result = new OC_OCS_Result($data, $statusCode); + $result = new OC_OCS_Result($data, $statusCode, $statusMessage); return $result; } - + /** * authenticate the api call * @param array $action the action details as supplied to OC_API::register() @@ -261,8 +263,8 @@ class OC_API { return false; break; } - } - + } + /** * http basic auth * @return string|false (username, or false on failure) @@ -294,7 +296,7 @@ class OC_API { return false; } - + /** * respond to a call * @param OC_OCS_Result $result @@ -343,5 +345,5 @@ class OC_API { } } } - + } |