Skip to content

Commit 5c38b45

Browse files
author
Björn Schießle
committed
improved error messages
1 parent f339729 commit 5c38b45

File tree

3 files changed

+27
-21
lines changed

3 files changed

+27
-21
lines changed

apps/federatedfilesharing/lib/FederatedShareProvider.php

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -171,43 +171,40 @@ public function create(IShare $share) {
171171
try {
172172
$uidOwner = $remoteShare['owner'] . '@' . $remoteShare['remote'];
173173
$shareId = $this->addShareToDB($itemSource, $itemType, $shareWith, $sharedBy, $uidOwner, $permissions, 'tmp_token_' . time());
174+
$share->setId($shareId);
174175
list($token, $remoteId) = $this->askOwnerToReShare($shareWith, $share, $shareId);
175176
// remote share was create successfully if we get a valid token as return
176177
$send = is_string($token) && $token !== '';
177-
if ($send) {
178-
$this->updateSuccessfulReshare($shareId, $token);
179-
$this->storeRemoteId($shareId, $remoteId);
180-
}
181178
} catch (\Exception $e) {
182179
// fall back to old re-share behavior if the remote server
183180
// doesn't support flat re-shares (was introduced with ownCloud 9.1)
184-
$data = $this->getRawShare($shareId);
185-
$brokenShare = $this->createShareObject($data);
186-
$this->removeShareFromTable($brokenShare);
187-
list($shareId, $send) = $this->createFederatedShare($share);
181+
$this->removeShareFromTable($share);
182+
$this->createFederatedShare($share);
188183
}
184+
if ($send) {
185+
$this->updateSuccessfulReshare($shareId, $token);
186+
$this->storeRemoteId($shareId, $remoteId);
187+
} else {
188+
$this->removeShareFromTable($share);
189+
$message_t = $this->l->t('File is already shared with %s', [$shareWith]);
190+
throw new \Exception($message_t);
191+
}
192+
189193
} else {
190-
list($shareId, $send) = $this->createFederatedShare($share);
194+
$this->createFederatedShare($share);
191195
}
192196

193197
$data = $this->getRawShare($shareId);
194-
$share = $this->createShareObject($data);
195-
196-
if ($send === false) {
197-
$this->removeShareFromTable($share);
198-
$message_t = $this->l->t('Sharing %s failed, could not find %s, maybe the server is currently unreachable.',
199-
[$share->getNode()->getName(), $shareWith]);
200-
throw new \Exception($message_t);
201-
}
202-
203-
return $share;
198+
return $this->createShareObject($data);
204199
}
205200

206201
/**
207202
* create federated share and inform the recipient
208203
*
209204
* @param IShare $share
210205
* @return array
206+
* @throws ShareNotFound
207+
* @throws \Exception
211208
*/
212209
protected function createFederatedShare(IShare $share) {
213210
$token = $this->tokenHandler->generateToken();
@@ -235,7 +232,15 @@ protected function createFederatedShare(IShare $share) {
235232
$sharedByFederatedId
236233
);
237234

238-
return [$shareId, $send];
235+
if ($send === false) {
236+
$data = $this->getRawShare($shareId);
237+
$share = $this->createShareObject($data);
238+
$this->removeShareFromTable($share);
239+
$message_t = $this->l->t('Sharing %s failed, could not find %s, maybe the server is currently unreachable.',
240+
[$share->getNode()->getName(), $share->getSharedWith()]);
241+
throw new \Exception($message_t);
242+
}
243+
239244
}
240245

241246
/**

apps/federatedfilesharing/lib/Notifications.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,7 @@ protected function getTimestamp() {
272272
* @param string $urlSuffix
273273
* @param array $fields post parameters
274274
* @return array
275+
* @throws \Exception
275276
*/
276277
protected function tryHttpPostToShareEndpoint($remoteDomain, $urlSuffix, array $fields) {
277278
$client = $this->httpClientService->newClient();

apps/federatedfilesharing/lib/RequestHandler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ public function reShare($params) {
243243
$this->federatedShareProvider->storeRemoteId((int)$result->getId(), $remoteId);
244244
return new \OC_OCS_Result(['token' => $result->getToken(), 'remoteId' => $result->getId()]);
245245
} catch (\Exception $e) {
246-
return new \OC_OCS_Result(null, Http::STATUS_INTERNAL_SERVER_ERROR);
246+
return new \OC_OCS_Result(null, Http::STATUS_BAD_REQUEST);
247247
}
248248
} else {
249249
return new \OC_OCS_Result(null, Http::STATUS_FORBIDDEN);

0 commit comments

Comments
 (0)