Skip to content

Commit 319216c

Browse files
authored
Merge pull request #52075 from nextcloud/fix/sharing-error-catch
fix(files_sharing): fix share creation error handling
2 parents 8357469 + 309d568 commit 319216c

14 files changed

+33
-13
lines changed

apps/files_sharing/lib/Controller/ShareAPIController.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
use OCP\Lock\LockedException;
5353
use OCP\Mail\IMailer;
5454
use OCP\Server;
55+
use OCP\Share\Exceptions\GenericShareException;
5556
use OCP\Share\Exceptions\ShareNotFound;
5657
use OCP\Share\Exceptions\ShareTokenException;
5758
use OCP\Share\IManager;
@@ -800,6 +801,9 @@ public function createShare(
800801
} catch (HintException $e) {
801802
$code = $e->getCode() === 0 ? 403 : $e->getCode();
802803
throw new OCSException($e->getHint(), $code);
804+
} catch (GenericShareException|\InvalidArgumentException $e) {
805+
$this->logger->error($e->getMessage(), ['exception' => $e]);
806+
throw new OCSForbiddenException($e->getMessage(), $e);
803807
} catch (\Exception $e) {
804808
$this->logger->error($e->getMessage(), ['exception' => $e]);
805809
throw new OCSForbiddenException('Failed to create share.', $e);

apps/files_sharing/src/mixins/ShareRequests.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@
66
// TODO: remove when ie not supported
77
import 'url-search-params-polyfill'
88

9+
import { emit } from '@nextcloud/event-bus'
10+
import { showError } from '@nextcloud/dialogs'
911
import { generateOcsUrl } from '@nextcloud/router'
1012
import axios from '@nextcloud/axios'
13+
1114
import Share from '../models/Share.ts'
12-
import { emit } from '@nextcloud/event-bus'
1315

1416
const shareUrl = generateOcsUrl('apps/files_sharing/api/v1/shares')
1517

@@ -45,7 +47,7 @@ export default {
4547
} catch (error) {
4648
console.error('Error while creating share', error)
4749
const errorMessage = error?.response?.data?.ocs?.meta?.message
48-
OC.Notification.showTemporary(
50+
showError(
4951
errorMessage ? t('files_sharing', 'Error creating the share: {errorMessage}', { errorMessage }) : t('files_sharing', 'Error creating the share'),
5052
{ type: 'error' },
5153
)

apps/files_sharing/src/views/SharingDetailsTab.vue

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,7 @@
251251
</NcButton>
252252
<NcButton type="primary"
253253
data-cy-files-sharing-share-editor-action="save"
254+
:disabled="creating"
254255
@click="saveShare">
255256
{{ shareButtonText }}
256257
<template v-if="creating" #icon>
@@ -1003,8 +1004,16 @@ export default {
10031004
incomingShare.password = this.share.password
10041005
}
10051006
1006-
this.creating = true
1007-
const share = await this.addShare(incomingShare)
1007+
let share
1008+
try {
1009+
this.creating = true
1010+
share = await this.addShare(incomingShare)
1011+
} catch (error) {
1012+
this.creating = false
1013+
// Error is already handled by ShareRequests mixin
1014+
return
1015+
}
1016+
10081017
// ugly hack to make code work - we need the id to be set but at the same time we need to keep values we want to update
10091018
this.share._share.id = share.id
10101019
await this.queueUpdate(...permissionsAndAttributes)
@@ -1018,6 +1027,7 @@ export default {
10181027
}
10191028
}
10201029
}
1030+
10211031
this.share = share
10221032
this.creating = false
10231033
this.$emit('add:share', this.share)

dist/4542-4542.js

Lines changed: 0 additions & 2 deletions
This file was deleted.

dist/4542-4542.js.map

Lines changed: 0 additions & 1 deletion
This file was deleted.

dist/4542-4542.js.map.license

Lines changed: 0 additions & 1 deletion
This file was deleted.

dist/4672-4672.js

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
File renamed without changes.

dist/4672-4672.js.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/4672-4672.js.map.license

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
4672-4672.js.license

0 commit comments

Comments
 (0)