diff --git a/lib/Exceptions/ConflictException.php b/lib/Exceptions/ConflictException.php new file mode 100644 index 000000000..b44bff031 --- /dev/null +++ b/lib/Exceptions/ConflictException.php @@ -0,0 +1,36 @@ + + * + * @author Jakob Röhrl + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ + +namespace OCA\Deck; + + +class ConflictException extends \Exception { + + public function __construct($message) { + parent::__construct($message); + } + + public function getStatus() { + return 409; + } +} \ No newline at end of file diff --git a/lib/Service/FileService.php b/lib/Service/FileService.php index ec03db12c..02f3ab6bc 100644 --- a/lib/Service/FileService.php +++ b/lib/Service/FileService.php @@ -42,6 +42,7 @@ use OCP\IConfig; use OCP\IL10N; use OCP\ILogger; use OCP\IRequest; +use OCP\Deck\ConflictException; class FileService implements IAttachmentService { @@ -146,13 +147,14 @@ class FileService implements IAttachmentService { * @param Attachment $attachment * @throws NotPermittedException * @throws StatusException + * @throws ConflictException */ public function create(Attachment $attachment) { $file = $this->getUploadedFile(); $folder = $this->getFolder($attachment); $fileName = $file['name']; if ($folder->fileExists($fileName)) { - throw new StatusException('File already exists.'); + throw new ConflictException('File already exists.'); } $target = $folder->newFile($fileName); diff --git a/src/components/card/CardSidebarTabAttachments.vue b/src/components/card/CardSidebarTabAttachments.vue index ba9685fb3..8f53a2d56 100644 --- a/src/components/card/CardSidebarTabAttachments.vue +++ b/src/components/card/CardSidebarTabAttachments.vue @@ -80,14 +80,15 @@ export default { clickAddNewAttachmment() { this.$refs.localAttachments.click() }, - onLocalAttachmentSelected(e) { + async onLocalAttachmentSelected(e) { const bodyFormData = new FormData() bodyFormData.append('cardId', this.card.id) bodyFormData.append('type', 'deck_file') bodyFormData.append('file', e.target.files[0]) try { - this.$store.dispatch('createAttachment', { cardId: this.card.id, formData: bodyFormData }) + await this.$store.dispatch('createAttachment', { cardId: this.card.id, formData: bodyFormData }) } catch (e) { + console.log("doppelt") console.log(e) } }, diff --git a/src/services/AttachmentApi.js b/src/services/AttachmentApi.js index 241a98daa..751ccdca4 100644 --- a/src/services/AttachmentApi.js +++ b/src/services/AttachmentApi.js @@ -38,16 +38,12 @@ export class AttachmentApi { } async createAttachment({ cardId, formData }) { - try { - const response = await axios({ - method: 'POST', - url: this.url(`/cards/${cardId}/attachment`), - data: formData, - }) - return response.data - } catch (e) { - throw e - } + const response = await axios({ + method: 'POST', + url: this.url(`/cards/${cardId}/attachment`), + data: formData, + }) + return response.data } async deleteAttachment(attachment) {