mirror of
https://github.com/nextcloud/server.git
synced 2026-02-19 02:38:40 -05:00
Merge pull request #55151 from nextcloud/feature/share-api-enhanced-logging
refactor(ShareApiController): Add more error handling
This commit is contained in:
commit
335693e4bb
1 changed files with 25 additions and 55 deletions
|
|
@ -1748,66 +1748,36 @@ class ShareAPIController extends OCSController {
|
|||
* @throws ShareNotFound
|
||||
*/
|
||||
private function getShareById(string $id): IShare {
|
||||
$share = null;
|
||||
$providers = [
|
||||
'ocinternal' => null, // No type check needed
|
||||
'ocCircleShare' => IShare::TYPE_CIRCLE,
|
||||
'ocMailShare' => IShare::TYPE_EMAIL,
|
||||
'ocRoomShare' => null,
|
||||
'deck' => IShare::TYPE_DECK,
|
||||
'sciencemesh' => IShare::TYPE_SCIENCEMESH,
|
||||
];
|
||||
|
||||
// First check if it is an internal share.
|
||||
try {
|
||||
$share = $this->shareManager->getShareById('ocinternal:' . $id, $this->userId);
|
||||
return $share;
|
||||
} catch (ShareNotFound $e) {
|
||||
// Do nothing, just try the other share type
|
||||
// Add federated sharing as a provider only if it's allowed
|
||||
if ($this->shareManager->outgoingServer2ServerSharesAllowed()) {
|
||||
$providers['ocFederatedSharing'] = null; // No type check needed
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
if ($this->shareManager->shareProviderExists(IShare::TYPE_CIRCLE)) {
|
||||
$share = $this->shareManager->getShareById('ocCircleShare:' . $id, $this->userId);
|
||||
return $share;
|
||||
foreach ($providers as $prefix => $type) {
|
||||
try {
|
||||
if ($type === null || $this->shareManager->shareProviderExists($type)) {
|
||||
return $this->shareManager->getShareById($prefix . ':' . $id, $this->userId);
|
||||
}
|
||||
} catch (ShareNotFound $e) {
|
||||
// Do nothing, continue to next provider
|
||||
} catch (\Exception $e) {
|
||||
$this->logger->warning('Unexpected error in share provider', [
|
||||
'shareId' => $id,
|
||||
'provider' => $prefix,
|
||||
'exception' => $e,
|
||||
]);
|
||||
}
|
||||
} catch (ShareNotFound $e) {
|
||||
// Do nothing, just try the other share type
|
||||
}
|
||||
|
||||
try {
|
||||
if ($this->shareManager->shareProviderExists(IShare::TYPE_EMAIL)) {
|
||||
$share = $this->shareManager->getShareById('ocMailShare:' . $id, $this->userId);
|
||||
return $share;
|
||||
}
|
||||
} catch (ShareNotFound $e) {
|
||||
// Do nothing, just try the other share type
|
||||
}
|
||||
|
||||
try {
|
||||
$share = $this->shareManager->getShareById('ocRoomShare:' . $id, $this->userId);
|
||||
return $share;
|
||||
} catch (ShareNotFound $e) {
|
||||
// Do nothing, just try the other share type
|
||||
}
|
||||
|
||||
try {
|
||||
if ($this->shareManager->shareProviderExists(IShare::TYPE_DECK)) {
|
||||
$share = $this->shareManager->getShareById('deck:' . $id, $this->userId);
|
||||
return $share;
|
||||
}
|
||||
} catch (ShareNotFound $e) {
|
||||
// Do nothing, just try the other share type
|
||||
}
|
||||
|
||||
try {
|
||||
if ($this->shareManager->shareProviderExists(IShare::TYPE_SCIENCEMESH)) {
|
||||
$share = $this->shareManager->getShareById('sciencemesh:' . $id, $this->userId);
|
||||
return $share;
|
||||
}
|
||||
} catch (ShareNotFound $e) {
|
||||
// Do nothing, just try the other share type
|
||||
}
|
||||
|
||||
if (!$this->shareManager->outgoingServer2ServerSharesAllowed()) {
|
||||
throw new ShareNotFound();
|
||||
}
|
||||
$share = $this->shareManager->getShareById('ocFederatedSharing:' . $id, $this->userId);
|
||||
|
||||
return $share;
|
||||
throw new ShareNotFound();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Reference in a new issue