Skip to content

Commit

Permalink
Merge pull request #5497 from nextcloud/fix/node-written-exception
Browse files Browse the repository at this point in the history
fix: catch expected exception in event handler
  • Loading branch information
mejo- authored Mar 17, 2024
2 parents 9a19fa2 + e41c3f3 commit 0282002
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/Listeners/BeforeNodeWrittenListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

namespace OCA\Text\Listeners;

use OCA\Text\Exception\DocumentHasUnsavedChangesException;
use OCA\Text\Service\DocumentService;
use OCP\EventDispatcher\Event;
use OCP\EventDispatcher\IEventListener;
Expand All @@ -49,7 +50,11 @@ public function handle(Event $event): void {
if ($node instanceof File && $node->getMimeType() === 'text/markdown') {
if (!$this->documentService->isSaveFromText()) {
// Reset document session to avoid manual conflict resolution if there's no unsaved steps
$this->documentService->resetDocument($node->getId());
try {
$this->documentService->resetDocument($node->getId());
} catch (DocumentHasUnsavedChangesException) {
// Do not throw during event handling in this is expected to happen
}
}
}
}
Expand Down

0 comments on commit 0282002

Please sign in to comment.