Skip to content

Commit eb8eb93

Browse files
committed
fix: throw FederationRequestError instead of generic Exception
Signed-off-by: Benjamin Frueh <benjamin.frueh@gmail.com>
1 parent 55bae93 commit eb8eb93

5 files changed

Lines changed: 32 additions & 15 deletions

File tree

lib/AppInfo/Application.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,10 @@
5050
use OCP\Federation\ICloudFederationProvider;
5151
use OCP\Federation\ICloudFederationProviderManager;
5252
use OCP\Group\Events\GroupDeletedEvent;
53+
use OCP\Navigation\Events\LoadAdditionalEntriesEvent;
5354
use OCP\OCM\Events\LocalOCMDiscoveryEvent;
5455
use OCP\Security\Signature\ISignatoryManager;
5556
use OCP\Server;
56-
use OCP\Navigation\Events\LoadAdditionalEntriesEvent;
5757
use OCP\Share\ShareReview\RegisterShareReviewSourceEvent;
5858
use OCP\User\Events\BeforeUserDeletedEvent;
5959
use OCP\User\Events\UserDeletedEvent;
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
7+
* SPDX-License-Identifier: AGPL-3.0-or-later
8+
*/
9+
10+
namespace OCA\Tables\Errors;
11+
12+
class FederationRequestError extends \Exception {
13+
}

lib/Federation/FederationProxy.php

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use GuzzleHttp\Exception\ServerException;
1414
use OC\Http\Client\Response;
1515
use OCA\Tables\Db\Share;
16+
use OCA\Tables\Errors\FederationRequestError;
1617
use OCP\AppFramework\Http;
1718
use OCP\Federation\ICloudFederationFactory;
1819
use OCP\Federation\ICloudFederationProviderManager;
@@ -70,7 +71,7 @@ protected function prependProtocolIfNotAvailable(string $url): string {
7071

7172
/**
7273
* @param 'get'|'post'|'put'|'delete' $verb
73-
* @throws \Exception
74+
* @throws FederationRequestError
7475
*/
7576
protected function request(
7677
string $verb,
@@ -93,17 +94,16 @@ protected function request(
9394
$body->rewind();
9495

9596
if (!is_array(json_decode($content, true))) {
96-
throw new \Exception('Error parsing JSON response', $status);
97+
throw new FederationRequestError('Error parsing JSON response', $status);
9798
}
9899

99100
$this->logger->debug('Client error from remote', ['exception' => $e]);
100101

101102
/** @psalm-suppress InvalidReturnStatement */
102103
return new Response($e->getResponse(), false);
103104
} catch (ServerException|\Throwable $e) {
104-
$serverException = new \Exception($e->getMessage(), $e->getCode(), $e);
105-
$this->logger->error('Could not reach remote', ['exception' => $serverException]);
106-
throw $serverException;
105+
$this->logger->error('Could not reach remote', ['exception' => $e]);
106+
throw new FederationRequestError('Could not reach remote: ' . $e->getMessage(), $e->getCode(), $e);
107107
}
108108
}
109109

@@ -123,6 +123,9 @@ public function delete(string $shareToken, string $url): IResponse {
123123
return $this->request('delete', $shareToken, $url);
124124
}
125125

126+
/**
127+
* @throws FederationRequestError
128+
*/
126129
public function getOCSData(IResponse $response, array $allowedStatusCodes = [Http::STATUS_OK]): array {
127130
if (!in_array($response->getStatusCode(), $allowedStatusCodes, true)) {
128131
$this->logger->debug('Unexpected status code ' . $response->getStatusCode());
@@ -132,11 +135,11 @@ public function getOCSData(IResponse $response, array $allowedStatusCodes = [Htt
132135
$content = $response->getBody();
133136
$responseData = json_decode($content, true, flags: JSON_THROW_ON_ERROR);
134137
if (!is_array($responseData)) {
135-
throw new \RuntimeException('JSON response is not an array');
138+
throw new FederationRequestError('JSON response is not an array');
136139
}
137140
} catch (\Throwable $e) {
138141
$this->logger->error('Error parsing JSON response', ['exception' => $e]);
139-
throw new \Exception('Error parsing JSON response', $e->getCode(), $e);
142+
throw new FederationRequestError('Error parsing JSON response', $e->getCode(), $e);
140143
}
141144

142145
return $responseData['ocs']['data'] ?? [];

lib/Middleware/ShareControlMiddleware.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@
2525
use OCP\Federation\ICloudIdManager;
2626
use OCP\IRequest;
2727
use OCP\ISession;
28-
use OCP\Share\IManager as ShareManager;
2928
use OCP\OCM\IOCMDiscoveryService;
29+
use OCP\Share\IManager as ShareManager;
3030
use ReflectionMethod;
3131

3232
class ShareControlMiddleware extends Middleware {

src/modules/sidebar/partials/ShareForm.vue

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,15 +59,16 @@ export default {
5959
},
6060
},
6161
62-
data() {
63-
return {
64-
selectedShare: null,
65-
}
66-
},
67-
6862
emits: [
6963
'add',
7064
],
65+
66+
data() {
67+
return {
68+
selectedShare: null,
69+
}
70+
},
71+
7172
computed: {
7273
...mapState(useTablesStore, ['tables', 'showSidebar', 'isLoadingSomething']),
7374

0 commit comments

Comments
 (0)