From de706b439874975c9849fc7c7ecf4b7cb66ce4e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julius=20H=C3=A4rtl?= Date: Wed, 25 Nov 2020 10:00:33 +0100 Subject: Catch possible database exceptions when fetching document data MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Julius Härtl --- lib/Service/ApiService.php | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) (limited to 'lib') diff --git a/lib/Service/ApiService.php b/lib/Service/ApiService.php index d318c1520..bae813649 100644 --- a/lib/Service/ApiService.php +++ b/lib/Service/ApiService.php @@ -32,6 +32,7 @@ use OCA\Activity\Data; use OCA\Text\DocumentHasUnsavedChangesException; use OCA\Text\DocumentSaveConflictException; use OCA\Text\VersionMismatchException; +use OCP\AppFramework\Db\DoesNotExistException; use OCP\AppFramework\Http; use OCP\AppFramework\Http\DataResponse; use OCP\AppFramework\Http\FileDisplayResponse; @@ -161,20 +162,25 @@ class ApiService { return new DataResponse(['steps' => []]); } - $result = [ - 'steps' => $this->documentService->getSteps($documentId, $version), - 'sessions' => $this->sessionService->getActiveSessions($documentId), - 'document' => $this->documentService->get($documentId) - ]; - - $session = $this->sessionService->getSession($documentId, $sessionId, $sessionToken); try { + $result = [ + 'steps' => $this->documentService->getSteps($documentId, $version), + 'sessions' => $this->sessionService->getActiveSessions($documentId), + 'document' => $this->documentService->get($documentId) + ]; + + $session = $this->sessionService->getSession($documentId, $sessionId, $sessionToken); $file = $this->documentService->getFileForSession($session, $token); } catch (NotFoundException $e) { $this->logger->logException($e, ['level' => ILogger::INFO]); return new DataResponse([ 'message' => 'File not found' ], 404); + } catch (DoesNotExistException $e) { + $this->logger->logException($e, ['level' => ILogger::INFO]); + return new DataResponse([ + 'message' => 'Document no longer exists' + ], 404); } try { -- cgit v1.2.3