Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Unify error responses and add logging where appropriate
Signed-off-by: Julius Härtl <[email protected]>
  • Loading branch information
juliusknorr authored and backportbot[bot] committed Jul 13, 2021
commit dca40288c4c16a2439a612db12697193f0db3aef
31 changes: 19 additions & 12 deletions lib/Controller/WorkspaceController.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@

namespace OCA\Text\Controller;

use Exception;
use OCA\Text\AppInfo\Application;
use OCA\Text\Service\SessionService;
use OCA\Text\Service\WorkspaceService;
Expand All @@ -60,11 +61,13 @@
use OCP\Files\Folder;
use OCP\Files\IRootFolder;
use OCP\Files\NotFoundException;
use OCP\Files\NotPermittedException;
use OCP\Files\StorageNotAvailableException;
use OCP\IRequest;
use OCP\IURLGenerator;
use OCP\Share\Exceptions\ShareNotFound;
use OCP\Share\IManager;
use Psr\Log\LoggerInterface;

class WorkspaceController extends OCSController {

Expand All @@ -89,7 +92,10 @@ class WorkspaceController extends OCSController {
/** @var IEventDispatcher */
private $eventDispatcher;

public function __construct($appName, IRequest $request, IRootFolder $rootFolder, IManager $shareManager, IDirectEditingManager $directEditingManager, IURLGenerator $urlGenerator, WorkspaceService $workspaceService, IEventDispatcher $eventDispatcher, $userId) {
/** @var LoggerInterface */
private $logger;

public function __construct($appName, IRequest $request, IRootFolder $rootFolder, IManager $shareManager, IDirectEditingManager $directEditingManager, IURLGenerator $urlGenerator, WorkspaceService $workspaceService, IEventDispatcher $eventDispatcher, LoggerInterface $logger, $userId) {
parent::__construct($appName, $request);
$this->rootFolder = $rootFolder;
$this->shareManager = $shareManager;
Expand All @@ -98,6 +104,7 @@ public function __construct($appName, IRequest $request, IRootFolder $rootFolder
$this->directEditingManager = $directEditingManager;
$this->urlGenerator = $urlGenerator;
$this->eventDispatcher = $eventDispatcher;
$this->logger = $logger;
}

/**
Expand Down Expand Up @@ -133,10 +140,11 @@ public function folder(string $path = '/'): DataResponse {
]
]);
}
} catch (NotFoundException $e) {
return new DataResponse(['message' => 'No valid folder found'], Http::STATUS_BAD_REQUEST);
} catch (StorageNotAvailableException $e) {
return new DataResponse(['message' => $e->getMessage()], Http::STATUS_INTERNAL_SERVER_ERROR);
} catch (NotFoundException | NotPermittedException $e) {
return new DataResponse(['message' => 'No workspace file found'], Http::STATUS_NOT_FOUND);
} catch (Exception $e) {
$this->logger->error('Failed to get workspace file', ['exception' => $e]);
return new DataResponse(['message' => 'No workspace file found'], Http::STATUS_NOT_FOUND);
}
}

Expand Down Expand Up @@ -166,12 +174,11 @@ public function publicFolder(string $shareToken, string $path = '/'): DataRespon
]
]);
}
} catch (NotFoundException $e) {
return new DataResponse(['message' => 'No valid folder found'], Http::STATUS_BAD_REQUEST);
} catch (ShareNotFound $e) {
return new DataResponse(['message' => 'No valid folder found'], Http::STATUS_BAD_REQUEST);
} catch (StorageNotAvailableException $e) {
return new DataResponse(['message' => $e->getMessage()], Http::STATUS_INTERNAL_SERVER_ERROR);
} catch (NotFoundException | ShareNotFound | StorageNotAvailableException $e) {
return new DataResponse(['message' => 'No workspace file found'], Http::STATUS_NOT_FOUND);
} catch (Exception $e) {
$this->logger->error('Failed to get public workspace file', ['exception' => $e]);
return new DataResponse(['message' => 'No workspace file found'], Http::STATUS_NOT_FOUND);
}
}

Expand All @@ -196,7 +203,7 @@ public function direct(string $path): DataResponse {
}

} catch (Exception $e) {
$this->logger->logException($e, ['message' => 'Exception when creating a new file through direct editing']);
$this->logger->error('Exception when creating a new file through direct editing', ['exception' => $e]);
return new DataResponse('Failed to create file', Http::STATUS_FORBIDDEN);
}
}
Expand Down