improved error messages

This commit is contained in:
Björn Schießle 2016-05-19 15:36:05 +02:00
parent e25fbaf65d
commit 06b6e2bff5
No known key found for this signature in database
GPG key ID: 2378A753E2BF04F6
3 changed files with 27 additions and 21 deletions

View file

@ -171,36 +171,31 @@ class FederatedShareProvider implements IShareProvider {
try {
$uidOwner = $remoteShare['owner'] . '@' . $remoteShare['remote'];
$shareId = $this->addShareToDB($itemSource, $itemType, $shareWith, $sharedBy, $uidOwner, $permissions, 'tmp_token_' . time());
$share->setId($shareId);
list($token, $remoteId) = $this->askOwnerToReShare($shareWith, $share, $shareId);
// remote share was create successfully if we get a valid token as return
$send = is_string($token) && $token !== '';
if ($send) {
$this->updateSuccessfulReshare($shareId, $token);
$this->storeRemoteId($shareId, $remoteId);
}
} catch (\Exception $e) {
// fall back to old re-share behavior if the remote server
// doesn't support flat re-shares (was introduced with ownCloud 9.1)
$data = $this->getRawShare($shareId);
$brokenShare = $this->createShareObject($data);
$this->removeShareFromTable($brokenShare);
list($shareId, $send) = $this->createFederatedShare($share);
$this->removeShareFromTable($share);
$this->createFederatedShare($share);
}
if ($send) {
$this->updateSuccessfulReshare($shareId, $token);
$this->storeRemoteId($shareId, $remoteId);
} else {
$this->removeShareFromTable($share);
$message_t = $this->l->t('File is already shared with %s', [$shareWith]);
throw new \Exception($message_t);
}
} else {
list($shareId, $send) = $this->createFederatedShare($share);
$this->createFederatedShare($share);
}
$data = $this->getRawShare($shareId);
$share = $this->createShareObject($data);
if ($send === false) {
$this->removeShareFromTable($share);
$message_t = $this->l->t('Sharing %s failed, could not find %s, maybe the server is currently unreachable.',
[$share->getNode()->getName(), $shareWith]);
throw new \Exception($message_t);
}
return $share;
return $this->createShareObject($data);
}
/**
@ -208,6 +203,8 @@ class FederatedShareProvider implements IShareProvider {
*
* @param IShare $share
* @return array
* @throws ShareNotFound
* @throws \Exception
*/
protected function createFederatedShare(IShare $share) {
$token = $this->tokenHandler->generateToken();
@ -235,7 +232,15 @@ class FederatedShareProvider implements IShareProvider {
$sharedByFederatedId
);
return [$shareId, $send];
if ($send === false) {
$data = $this->getRawShare($shareId);
$share = $this->createShareObject($data);
$this->removeShareFromTable($share);
$message_t = $this->l->t('Sharing %s failed, could not find %s, maybe the server is currently unreachable.',
[$share->getNode()->getName(), $share->getSharedWith()]);
throw new \Exception($message_t);
}
}
/**

View file

@ -272,6 +272,7 @@ class Notifications {
* @param string $urlSuffix
* @param array $fields post parameters
* @return array
* @throws \Exception
*/
protected function tryHttpPostToShareEndpoint($remoteDomain, $urlSuffix, array $fields) {
$client = $this->httpClientService->newClient();

View file

@ -251,7 +251,7 @@ class RequestHandler {
$this->federatedShareProvider->storeRemoteId((int)$result->getId(), $remoteId);
return new \OC_OCS_Result(['token' => $result->getToken(), 'remoteId' => $result->getId()]);
} catch (\Exception $e) {
return new \OC_OCS_Result(null, Http::STATUS_INTERNAL_SERVER_ERROR);
return new \OC_OCS_Result(null, Http::STATUS_BAD_REQUEST);
}
} else {
return new \OC_OCS_Result(null, Http::STATUS_FORBIDDEN);