diff options
-rw-r--r-- | lib/Controller/DirectViewController.php | 29 | ||||
-rw-r--r-- | lib/Controller/DocumentController.php | 31 | ||||
-rw-r--r-- | lib/Controller/SettingsController.php | 25 | ||||
-rw-r--r-- | lib/TemplateManager.php | 2 |
4 files changed, 35 insertions, 52 deletions
diff --git a/lib/Controller/DirectViewController.php b/lib/Controller/DirectViewController.php index b6c77a32..b837d39e 100644 --- a/lib/Controller/DirectViewController.php +++ b/lib/Controller/DirectViewController.php @@ -105,10 +105,7 @@ class DirectViewController extends Controller { try { $direct = $this->directMapper->getByToken($token); } catch (DoesNotExistException $e) { - $params = [ - 'errors' => [['error' => $e->getMessage()]] - ]; - $response = new TemplateResponse('core', 'error', $params, 'guest'); + $response = $this->renderErrorPage('Failed to open the requested file.'); $response->setStatus(Http::STATUS_FORBIDDEN); return $response; } @@ -154,10 +151,8 @@ class DirectViewController extends Controller { list($urlSrc, $token, $wopi) = $this->tokenManager->getToken($item->getId(), null, $direct->getUid(), true); } catch (\Exception $e) { - $params = [ - 'errors' => [['error' => $e->getMessage()]] - ]; - return new TemplateResponse('core', 'error', $params, 'guest'); + $this->logger->logException($e); + return $this->renderErrorPage('Failed to open the requested file.'); } $relativePath = $folder->getRelativePath($item->getPath()); @@ -183,10 +178,8 @@ class DirectViewController extends Controller { $response->setContentSecurityPolicy($policy); return $response; } catch (\Exception $e) { - $params = [ - 'errors' => [['error' => $e->getMessage()]] - ]; - return new TemplateResponse('core', 'error', $params, 'guest'); + $this->logger->logException($e); + return $this->renderErrorPage('Failed to open the requested file.'); } } @@ -242,13 +235,17 @@ class DirectViewController extends Controller { } } catch (\Exception $e) { $this->logger->logException($e, ['app'=>'richdocuments']); - $params = [ - 'errors' => [['error' => $e->getMessage()]] - ]; - return new TemplateResponse('core', 'error', $params, 'guest'); + $response = $this->renderErrorPage('Failed to open the requested file.'); } return new TemplateResponse('core', '403', [], 'guest'); } + + private function renderErrorPage($message) { + $params = [ + 'errors' => [['error' => $message]] + ]; + return new TemplateResponse('core', 'error', $params, 'guest'); + } } diff --git a/lib/Controller/DocumentController.php b/lib/Controller/DocumentController.php index bca32ffa..8ced26a7 100644 --- a/lib/Controller/DocumentController.php +++ b/lib/Controller/DocumentController.php @@ -148,10 +148,6 @@ class DocumentController extends Controller { ]; } catch (\Exception $e) { $this->logger->logException($e, ['app'=>'richdocuments']); - $params = [ - 'errors' => [['error' => $e->getMessage()]] - ]; - return new TemplateResponse('core', 'error', $params, 'guest'); } } } @@ -252,10 +248,7 @@ class DocumentController extends Controller { return $response; } catch (\Exception $e) { $this->logger->logException($e, ['app'=>'richdocuments']); - $params = [ - 'errors' => [['error' => $e->getMessage()]] - ]; - return new TemplateResponse('core', 'error', $params, 'guest'); + return $this->renderErrorPage('Failed to open the requested file.'); } } @@ -370,10 +363,7 @@ class DocumentController extends Controller { } } catch (\Exception $e) { $this->logger->logException($e, ['app'=>'richdocuments']); - $params = [ - 'errors' => [['error' => $e->getMessage()]] - ]; - return new TemplateResponse('core', 'error', $params, 'guest'); + return $this->renderErrorPage('Failed to open the requested file.'); } return new TemplateResponse('core', '403', [], 'guest'); @@ -420,10 +410,7 @@ class DocumentController extends Controller { } } catch (\Exception $e) { $this->logger->logException($e, ['app'=>'richdocuments']); - $params = [ - 'errors' => [['error' => $e->getMessage()]] - ]; - return new TemplateResponse('core', 'error', $params, 'guest'); + return $this->renderErrorPage('Failed to open the requested file.'); } return new TemplateResponse('core', '403', [], 'guest'); @@ -505,10 +492,7 @@ class DocumentController extends Controller { return new TemplateResponse('core', '404', [], 'guest'); } catch (\Exception $e) { $this->logger->logException($e, ['app'=>'richdocuments']); - $params = [ - 'errors' => [['error' => $e->getMessage()]] - ]; - return new TemplateResponse('core', 'error', $params, 'guest'); + return $this->renderErrorPage('Failed to open the requested file.'); } return new TemplateResponse('core', '403', [], 'guest'); @@ -614,4 +598,11 @@ class DocumentController extends Controller { 'message' => $this->l10n->t('Cannot create document') ]); } + + private function renderErrorPage($message) { + $params = [ + 'errors' => [['error' => $message]] + ]; + return new TemplateResponse('core', 'error', $params, 'guest'); + } } diff --git a/lib/Controller/SettingsController.php b/lib/Controller/SettingsController.php index bec87a4b..6107880b 100644 --- a/lib/Controller/SettingsController.php +++ b/lib/Controller/SettingsController.php @@ -20,6 +20,7 @@ use OCP\AppFramework\Http; use OCP\AppFramework\Http\DataResponse; use OCP\AppFramework\Http\JSONResponse; use OCP\AppFramework\Http\NotFoundResponse; +use OCP\ILogger; use \OCP\IRequest; use \OCP\IL10N; use OCA\Richdocuments\AppConfig; @@ -43,18 +44,9 @@ class SettingsController extends Controller{ private $capabilitiesService; /** @var DemoService */ private $demoService; + /** @var ILogger */ + private $logger; - /** - * @param string $appName - * @param IRequest $request - * @param IL10N $l10n - * @param AppConfig $appConfig - * @param IConfig $config - * @param DiscoveryManager $discoveryManager - * @param Parser $wopiParser - * @param string $userId - * @param CapabilitiesService $capabilitiesService - */ public function __construct($appName, IRequest $request, IL10N $l10n, @@ -62,9 +54,10 @@ class SettingsController extends Controller{ IConfig $config, DiscoveryManager $discoveryManager, Parser $wopiParser, - $userId, CapabilitiesService $capabilitiesService, - DemoService $demoService + DemoService $demoService, + ILogger $logger, + $userId ) { parent::__construct($appName, $request); $this->l10n = $l10n; @@ -72,9 +65,10 @@ class SettingsController extends Controller{ $this->config = $config; $this->discoveryManager = $discoveryManager; $this->wopiParser = $wopiParser; - $this->userId = $userId; $this->capabilitiesService = $capabilitiesService; $this->demoService = $demoService; + $this->logger = $logger; + $this->userId = $userId; } /** @@ -86,9 +80,10 @@ class SettingsController extends Controller{ try { $response = $this->discoveryManager->fetchFromRemote(); } catch (\Exception $e) { + $this->logger->logException($e, ['app' => 'richdocuments']); return new DataResponse([ 'status' => $e->getCode(), - 'message' => $e->getMessage() + 'message' => 'Could not fetch discovery details' ], Http::STATUS_INTERNAL_SERVER_ERROR); } diff --git a/lib/TemplateManager.php b/lib/TemplateManager.php index 5edd0d16..b54848ff 100644 --- a/lib/TemplateManager.php +++ b/lib/TemplateManager.php @@ -409,7 +409,7 @@ class TemplateManager { try { $templateDir = $userFolder->get('Templates'); } catch (NotFoundException $e) { - throw new NotFoundException($e->getMessage()); + throw new NotFoundException('Template directory not found'); } } |